Rearrange datasync methods (#116)
This commit is contained in:
parent
775d17008e
commit
44e7fe793b
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
type DataSync struct {
|
||||
*datasyncnode.Node
|
||||
// DataSyncNodeTransport is the implemntation of the datasync transport interface
|
||||
// DataSyncNodeTransport is the implementation of the datasync transport interface.
|
||||
*DataSyncNodeTransport
|
||||
logger *zap.Logger
|
||||
sendingEnabled bool
|
||||
|
@ -23,14 +23,6 @@ func New(node *datasyncnode.Node, transport *DataSyncNodeTransport, sendingEnabl
|
|||
return &DataSync{Node: node, DataSyncNodeTransport: transport, sendingEnabled: sendingEnabled, logger: logger}
|
||||
}
|
||||
|
||||
func (d *DataSync) Add(publicKey *ecdsa.PublicKey, datasyncMessage datasyncproto.Payload) {
|
||||
packet := datasynctransport.Packet{
|
||||
Sender: datasyncpeer.PublicKeyToPeerID(*publicKey),
|
||||
Payload: datasyncMessage,
|
||||
}
|
||||
d.DataSyncNodeTransport.AddPacket(packet)
|
||||
}
|
||||
|
||||
func (d *DataSync) Handle(sender *ecdsa.PublicKey, payload []byte) [][]byte {
|
||||
var payloads [][]byte
|
||||
logger := d.logger.With(zap.String("site", "Handle"))
|
||||
|
@ -48,18 +40,26 @@ func (d *DataSync) Handle(sender *ecdsa.PublicKey, payload []byte) [][]byte {
|
|||
payloads = append(payloads, message.Body)
|
||||
}
|
||||
if d.sendingEnabled {
|
||||
d.Add(sender, datasyncMessage)
|
||||
d.add(sender, datasyncMessage)
|
||||
}
|
||||
}
|
||||
|
||||
return payloads
|
||||
}
|
||||
|
||||
func (d *DataSync) Stop() {
|
||||
d.Node.Stop()
|
||||
}
|
||||
|
||||
func (d *DataSync) add(publicKey *ecdsa.PublicKey, datasyncMessage datasyncproto.Payload) {
|
||||
packet := datasynctransport.Packet{
|
||||
Sender: datasyncpeer.PublicKeyToPeerID(*publicKey),
|
||||
Payload: datasyncMessage,
|
||||
}
|
||||
d.DataSyncNodeTransport.AddPacket(packet)
|
||||
}
|
||||
|
||||
func unwrap(payload []byte) (datasyncPayload datasyncproto.Payload, err error) {
|
||||
err = proto.Unmarshal(payload, &datasyncPayload)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *DataSync) Stop() {
|
||||
d.Node.Stop()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue