github.com/status-im/status-go@v1.1.0/eth-node/types/envelopes.go (about) 1 package types 2 3 // Envelope represents a clear-text data packet to transmit through the Whisper 4 // network. Its contents may or may not be encrypted and signed. 5 type Envelope interface { 6 Wrapped 7 8 Hash() Hash // cached hash of the envelope to avoid rehashing every time 9 Bloom() []byte 10 PoW() float64 11 Expiry() uint32 12 TTL() uint32 13 Topic() TopicType 14 Size() int 15 } 16 17 // EventType used to define known envelope events. 18 type EventType string 19 20 // NOTE: This list of event names is extracted from Geth. It must be kept in sync, or otherwise a mapping layer needs to be created 21 const ( 22 // EventEnvelopeSent fires when envelope was sent to a peer. 23 EventEnvelopeSent EventType = "envelope.sent" 24 // EventEnvelopeExpired fires when envelop expired 25 EventEnvelopeExpired EventType = "envelope.expired" 26 // EventEnvelopeReceived is sent once envelope was received from a peer. 27 // EventEnvelopeReceived must be sent to the feed even if envelope was previously in the cache. 28 // And event, ideally, should contain information about peer that sent envelope to us. 29 EventEnvelopeReceived EventType = "envelope.received" 30 // EventBatchAcknowledged is sent when batch of envelopes was acknowledged by a peer. 31 EventBatchAcknowledged EventType = "batch.acknowledged" 32 // EventEnvelopeAvailable fires when envelop is available for filters 33 EventEnvelopeAvailable EventType = "envelope.available" 34 // EventMailServerRequestSent fires when such request is sent. 35 EventMailServerRequestSent EventType = "mailserver.request.sent" 36 // EventMailServerRequestCompleted fires after mailserver sends all the requested messages 37 EventMailServerRequestCompleted EventType = "mailserver.request.completed" 38 // EventMailServerRequestExpired fires after mailserver the request TTL ends. 39 // This event is independent and concurrent to EventMailServerRequestCompleted. 40 // Request should be considered as expired only if expiry event was received first. 41 EventMailServerRequestExpired EventType = "mailserver.request.expired" 42 // EventMailServerEnvelopeArchived fires after an envelope has been archived 43 EventMailServerEnvelopeArchived EventType = "mailserver.envelope.archived" 44 // EventMailServerSyncFinished fires when the sync of messages is finished. 45 EventMailServerSyncFinished EventType = "mailserver.sync.finished" 46 ) 47 48 const ( 49 // EnvelopeTimeNotSynced represents the code passed to notify of a clock skew situation 50 EnvelopeTimeNotSynced uint = 1000 51 // EnvelopeOtherError represents the code passed to notify of a generic error situation 52 EnvelopeOtherError 53 ) 54 55 // EnvelopeEvent used for envelopes events. 56 type EnvelopeEvent struct { 57 Event EventType 58 Hash Hash 59 Batch Hash 60 Peer EnodeID 61 Data interface{} 62 } 63 64 // EnvelopeError code and optional description of the error. 65 type EnvelopeError struct { 66 Hash Hash 67 Code uint 68 Description string 69 } 70 71 // Subscription represents a stream of events. The carrier of the events is typically a 72 // channel, but isn't part of the interface. 73 // 74 // Subscriptions can fail while established. Failures are reported through an error 75 // channel. It receives a value if there is an issue with the subscription (e.g. the 76 // network connection delivering the events has been closed). Only one value will ever be 77 // sent. 78 // 79 // The error channel is closed when the subscription ends successfully (i.e. when the 80 // source of events is closed). It is also closed when Unsubscribe is called. 81 // 82 // The Unsubscribe method cancels the sending of events. You must call Unsubscribe in all 83 // cases to ensure that resources related to the subscription are released. It can be 84 // called any number of times. 85 type Subscription interface { 86 Err() <-chan error // returns the error channel 87 Unsubscribe() // cancels sending of events, closing the error channel 88 }