github.com/status-im/status-go@v1.1.0/waku/common/protocol.go (about) 1 package common 2 3 import ( 4 "net" 5 6 "github.com/ethereum/go-ethereum/common" 7 "github.com/ethereum/go-ethereum/p2p" 8 "github.com/ethereum/go-ethereum/p2p/enode" 9 "github.com/ethereum/go-ethereum/rlp" 10 ) 11 12 // Peer represents a remote Waku client with which the local host waku instance exchanges data / messages. 13 type Peer interface { 14 // Start performs the handshake and initialize the broadcasting of messages 15 Start() error 16 Stop() 17 // Run start the polling loop 18 Run() error 19 20 // NotifyAboutPowRequirementChange notifies the peer that POW for the host has changed 21 NotifyAboutPowRequirementChange(float64) error 22 // NotifyAboutBloomFilterChange notifies the peer that bloom filter for the host has changed 23 NotifyAboutBloomFilterChange([]byte) error 24 // NotifyAboutTopicInterestChange notifies the peer that topics for the host have changed 25 NotifyAboutTopicInterestChange([]TopicType) error 26 27 // SetPeerTrusted sets the value of trusted, meaning we will 28 // allow p2p messages from them, which is necessary to interact 29 // with mailservers. 30 SetPeerTrusted(bool) 31 // SetRWWriter sets the socket to read/write 32 SetRWWriter(p2p.MsgReadWriter) 33 34 RequestHistoricMessages(*Envelope) error 35 SendHistoricMessageResponse([]byte) error 36 SendP2PMessages([]*Envelope) error 37 SendRawP2PDirect([]rlp.RawValue) error 38 39 SendBundle(bundle []*Envelope) (rst common.Hash, err error) 40 41 // Mark marks an envelope known to the peer so that it won't be sent back. 42 Mark(*Envelope) 43 // Marked checks if an envelope is already known to the remote peer. 44 Marked(*Envelope) bool 45 46 ID() []byte 47 IP() net.IP 48 EnodeID() enode.ID 49 50 PoWRequirement() float64 51 BloomFilter() []byte 52 ConfirmationsEnabled() bool 53 } 54 55 // WakuHost is the local instance of waku, which both interacts with remote clients 56 // (peers) and local clients (through RPC API) 57 type WakuHost interface { 58 // HandlePeer handles the connection of a new peer 59 HandlePeer(Peer, p2p.MsgReadWriter) error 60 // MaxMessageSize returns the maximum accepted message size. 61 MaxMessageSize() uint32 62 // LightClientMode returns whether the host is running in light client mode 63 LightClientMode() bool 64 // Mailserver returns whether the host is running a mailserver 65 Mailserver() bool 66 // LightClientModeConnectionRestricted indicates that connection to light client in light client mode not allowed 67 LightClientModeConnectionRestricted() bool 68 // ConfirmationsEnabled returns true if message confirmations are enabled. 69 ConfirmationsEnabled() bool 70 // PacketRateLimits returns the current rate limits for the host 71 PacketRateLimits() RateLimits 72 // BytesRateLimits returns the current rate limits for the host 73 BytesRateLimits() RateLimits 74 // MinPow returns the MinPow for the host 75 MinPow() float64 76 // BloomFilterMode returns whether the host is using bloom filter 77 BloomFilterMode() bool 78 // BloomFilter returns the bloom filter for the host 79 BloomFilter() []byte 80 //TopicInterest returns the topics for the host 81 TopicInterest() []TopicType 82 // IsEnvelopeCached checks if envelope with specific hash has already been received and cached. 83 IsEnvelopeCached(common.Hash) bool 84 // Envelopes returns all the envelopes queued 85 Envelopes() []*Envelope 86 SendEnvelopeEvent(EnvelopeEvent) int 87 // OnNewEnvelopes handles newly received envelopes from a peer 88 OnNewEnvelopes([]*Envelope, Peer) ([]EnvelopeError, error) 89 // OnNewP2PEnvelopes handles envelopes received though the P2P 90 // protocol (i.e from a mailserver in most cases) 91 OnNewP2PEnvelopes([]*Envelope) error 92 // OnMessagesResponse handles when the peer receive a message response 93 // from a mailserver 94 OnMessagesResponse(MessagesResponse, Peer) error 95 // OnMessagesRequest handles when the peer receive a message request 96 // this only works if the peer is a mailserver 97 OnMessagesRequest(MessagesRequest, Peer) error 98 // OnDeprecatedMessagesRequest handles when the peer receive a message request 99 // using the *Envelope format. Currently the only production client (status-mobile) 100 // is exclusively using this one. 101 OnDeprecatedMessagesRequest(*Envelope, Peer) error 102 103 OnBatchAcknowledged(common.Hash, Peer) error 104 OnP2PRequestCompleted([]byte, Peer) error 105 }