Andrea Maria Piana e65760ca85 Add basic peersyncing
This commit adds basic syncing capabilities with peers if they are both
online.

It updates the work done on MVDS, but I decided to create the code in
status-go instead, since it's very tight to the application (similarly
the code that was the inspiration for mvds, bramble, is all tight
together at the database level).

I reused parts of the protobufs.

The flow is:

1) An OFFER message is sent periodically with a bunch of message-ids and
   group-ids.
2) Anyone can REQUEST some of those messages if not present in their
   database.

3) The peer will then send over those messages.

It's disabled by default, but I am planning to add a way to set up the
flags.
2024-01-23 12:46:17 +00:00

31 lines
718 B
Go

package datasync
import (
"crypto/ecdsa"
"github.com/status-im/mvds/state"
"github.com/status-im/status-go/eth-node/crypto"
)
func ToGroupID(data []byte) state.GroupID {
g := state.GroupID{}
copy(g[:], data[:])
return g
}
// ToOneToOneGroupID returns a groupID for a onetoonechat, which is taken by
// concatenating the bytes of the compressed keys, in ascending order by X
func ToOneToOneGroupID(key1 *ecdsa.PublicKey, key2 *ecdsa.PublicKey) state.GroupID {
pk1 := crypto.CompressPubkey(key1)
pk2 := crypto.CompressPubkey(key2)
var groupID []byte
if key1.X.Cmp(key2.X) == -1 {
groupID = append(pk1, pk2...)
} else {
groupID = append(pk2, pk1...)
}
return ToGroupID(crypto.Keccak256(groupID))
}