status-im / status-console-client

Status messaging console user interface
Mozilla Public License 2.0
10 stars 2 forks source link

add possiblity for custom decoders in WhisperServiceAdapter #81

Closed adambabik closed 5 years ago

adambabik commented 5 years ago

@decanus would this change help with removing custom transport for data sync? I imagine it would work like this:

// already exists
adapter := adapters.NewWhisperServiceAdapter(statusNode, shhService, pk)

if *ds {
// setup datasync
mvds = ...

adapter.SetDecoder(mvds.MessageHandler)
}

mvds.MessageHandler would need to have a signature like this: func(data []byte) (protocol.Message, error) and I imagine that it would first decode bytes to whatever you use to serialize data, extract metadata needed for data sync logic and return protocol.Message.

decanus commented 5 years ago

@adambabik So the problem is also the other messages we send around for data sync, like OFFER, REQUEST and ACKs. Would that work with this?

adambabik commented 5 years ago

@decanus yes, it's up to you what to do with a message. However, in this particular change, I need to add message skipping. OFFER and others would be decoded and handled by your decoder but not necessarily result in a valid protocol.Message.

I will add this in a moment.

adambabik commented 5 years ago

I am closing this because we need more refactoring:

  1. Currently, Whisper adapters use protocol package and return protocol.Message. That's too specific. We should rename adapters package to transports and they should not import protocol package at all to support any protocol.
  2. Instead, Messenger should accept a protocol object or protocol adapter object that would translate raw values incoming from transports into protocol-specific objects.
  3. Any translations between protocol options and transport options would happen in the protocol adapter. Currently, protocol options are used directly in the adapters (transports).