Skip to content

Changing Push Protocol to Pull protocol for transferring Messages.

Manav Sarkar requested to merge ManavSarkar/p2p-messaging-flutter:main into gsoc-2022

The application initially was implemented with the Push protocol which has some limitations as discussed in the proposal. So the protocol is changed to the Pull protocol.

The approach taken is as follows(Considering two devices connected):

  1. First the last message id that was received is broadcasted(propagated) to the connected device. The message contains the last message id and the receiver's name. The message is of type Update so that the message is not saved to the database.
  2. At the receiver end, the message id received from update is compared to the last message id that was sent. If the tables are up to date, then they should be the same. If not, then the broadcast function is called that broadcasts the messages in the cache. Else it remains the same.
  3. This process continues until they have the updated database.
  4. The broadcasting last message-id is done every message interval.

Changes:

  1. Created a function getLastMessageId() in the MessageDB file which takes the parameter of the type of message, i.e. received or sent. The purpose is used to get the id of the last message from the Database.
  2. Created a function broadcastLastMessageId() in the Adhoc file whose purpose is to regularly send update messages to the connected devices. The update message contained only the id of the last message received.
  3. Created a function compareMessageId() in the Adhoc file whose purpose is to compare the id of the last message sent and that one received from the update message from the connected device. If they are not the same, the messages in the cache are broadcasted.
  4. The checkDevices() function in the DeviceListScreen file is the code separated from the init() function for code simplification.
  5. UI refinement in the DeviceListScreen and other code changes related to documenting the functions.

Hence the protocol is transferred successfully to the Pull protocol.

Edited by Manav Sarkar

Merge request reports