github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/id_translator.go (about) 1 package p2p 2 3 import ( 4 "errors" 5 6 "github.com/libp2p/go-libp2p/core/peer" 7 8 "github.com/onflow/flow-go/model/flow" 9 ) 10 11 var ( 12 // ErrInvalidId indicates that the given ID (either `peer.ID` or `flow.Identifier`) has an invalid format. 13 ErrInvalidId = errors.New("empty peer ID") 14 15 // ErrUnknownId indicates that the given ID (either `peer.ID` or `flow.Identifier`) is unknown. 16 ErrUnknownId = errors.New("unknown ID") 17 ) 18 19 // IDTranslator provides an interface for converting from Flow ID's to LibP2P peer ID's 20 // and vice versa. 21 type IDTranslator interface { 22 // GetPeerID returns the peer ID for the given `flow.Identifier`. 23 // During normal operations, the following error returns are expected 24 // * ErrUnknownId if the given Identifier is unknown 25 // * ErrInvalidId if the given Identifier has an invalid format. 26 // This error return is only possible, when the Identifier is generated from some 27 // other input (e.g. the node's public key). While the Flow protocol itself makes 28 // no assumptions about the structure of the `Identifier`, protocol extensions 29 // (e.g. for Observers) might impose a strict relationship between both flow 30 // Identifier and peer ID, in which case they can use this error. 31 // TODO: implementations do not fully adhere to this convention on error returns 32 GetPeerID(flow.Identifier) (peer.ID, error) 33 34 // GetFlowID returns the `flow.Identifier` for the given `peer.ID`. 35 // During normal operations, the following error returns are expected 36 // * ErrUnknownId if the given Identifier is unknown 37 // * ErrInvalidId if the given Identifier has an invalid format. 38 // This error return is only possible, when the Identifier is generated from some 39 // other input (e.g. the node's public key). While the Flow protocol itself makes 40 // no assumptions about the structure of the `Identifier`, protocol extensions 41 // (e.g. for Observers) might impose a strict relationship between both flow 42 // Identifier and peer ID, in which case they can use this error. 43 // TODO: implementations do not fully adhere to this convention on error returns 44 GetFlowID(peer.ID) (flow.Identifier, error) 45 }