Layered View
![Layer diagram](images/layers.jpg)
The 3 layers of our design include:
1. Connection Manager - responsible for connection and handshake with all peers.
2. Routing Manager - responsible for epidemic routing of all messages by a simple store and forward mechanism.
3. File Discover Manager - responsible for submitting and handling file requests from other devices.
A brief explanation of what each file does is given below.
P2PWifiDirectActivity.java
- This is our main activity file which has the console, the list view and the tabs for the 3 managers.
P2PConnectionAdapter.java
- This file gives the list view of all possible connections.
P2PConnectionManager.java
- This is our Connection Manager class.We first grab the MAC address,then set up the scan alarm which repeats every 5 seconds when scanning is on. We have an intent filter where we register to receive android wifi p2p intents connection intents and the scan alarm.This class has the following methods:discoverPeers- once this is called, android throws a PEERS_CHANGED_EVENT if successful
startDiscovery- allow manager to discover peers and connect to other devices
stopDiscovery- stop trying to connect to other devices
closeConnections- removes all connections associated with the channel then calls the disconnect method of each connection
onFailure- this is the callback when an android framework call is not successful
onReceive- this is the method that gets called when a broadcast intent is thrown by the android framework that we registered for during initialization
After a success full discoverPeers call, we get the peer list via the onPeersChanged callback. When a connection is established/broken we grab the network info object and check if a connection was established.
onPeersAvailable - this is the callback from the requestPeers call. This creates a new P2PConenction object based on a null device set the device when we loop through the peers P2PConnection has overridden the equals method so we can compare two objects based on their underlying WifiP2PDevice.
createNewP2PConnection - this is the callback from the clienthandshake/serverhandshake asynctask. clienthandshake/serverhandshake asynctask set up the handshake mechanism between the connected phones.
P2PConnection.java
- This is where we have the connection info and thereby call either sendMessage service or the receiveMessage service.
P2PRoutingManager.java
- This file defines our routing manager class.The routing manager has an intent register which registers the following intents:
newConnection - When we have a new connection where in all the messages are forwarded.
MessageReceived - this intent is passed when we have an incoming message.
OutgoingApplicationMessage - This intent is passed when the routing manager receives an outgoing application message that needs to be forwarded to all peers.
P2PMessage.java
- This defines the message format for the outgoing and incoming messages.
P2PMessageAdapter.java
- This provides a listview for the messages.
P2PSendMessage.java
- SendMessage service.
P2PReceiveMessage.java
- ReceiveMessage service.
P2PFileDiscoveryManager.java
- This manager registers incomingApplicationMessage or OutgoingApplicationMessage intents. It then checks where exactly the file is located in the device and returns an appropriate response.
P2PFileRequest.java
- This defines the filerequest class.
P2PFileRequestAdapter.java
- provides a listview for the requested files.
Our Contributions to multi-hop messaging over Wifi-direct
- Handshaking protocol is created at the connection layer which has peers exchange necessary information (ports/IP/MAC) that Wifi Direct doesn't provide (only provides info about group owner)
- A messaging service at the routing layer whose messages are easy to extend and whose service is easy to implement and use
- We've shown how to pass intents and data between layers so that future developers can easily build out their own layers which implement more advanced management techniques
- A file request and searching service at file manager layer allows users to send a file request to peers, and search file in their local phone for peers’ file request.