Documentation ¶
Index ¶
- Constants
- Variables
- func DisconnectReasonMaxSize() (s int)
- func IdentityChallengeMaxSize() (s int)
- func IdentityChallengeResponseMaxSize() (s int)
- func IdentityChallengeResponseSignedMaxSize() (s int)
- func IdentityChallengeSignedMaxSize() (s int)
- func IdentityChallengeValueMaxSize() (s int)
- func IdentityVerificationMessageMaxSize() (s int)
- func IdentityVerificationMessageSignedMaxSize() (s int)
- func MarshallMessageOfInterest(messageTags []protocol.Tag) []byte
- func MarshallMessageOfInterestMap(tagmap map[protocol.Tag]bool) []byte
- func MessageOfInterestMaxSize() int
- func NewIdentityChallengeScheme(dn string) *identityChallengePublicKeyScheme
- func NewIdentityTracker() *publicKeyIdentTracker
- func ParseHostOrURL(addr string) (*url.URL, error)
- func ParseHostOrURLOrMultiaddr(addr string) (string, error)
- func SetUserAgentHeader(header http.Header)
- type Dialer
- type ForwardingPolicy
- type GossipNode
- type HTTPPeer
- type HandlerFunc
- type IPAddressable
- type IncomingMessage
- type LimitedReaderSlurper
- type MessageHandler
- type Multiplexer
- type NetPrioScheme
- type NodeInfo
- type OutgoingMessage
- type P2PNetwork
- func (n *P2PNetwork) Address() (string, bool)
- func (n *P2PNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
- func (n *P2PNetwork) ClearHandlers()
- func (n *P2PNetwork) Disconnect(badnode Peer)
- func (n *P2PNetwork) DisconnectPeers()
- func (n *P2PNetwork) GetGenesisID() string
- func (n *P2PNetwork) GetHTTPRequestConnection(request *http.Request) (conn net.Conn)
- func (n *P2PNetwork) GetPeers(options ...PeerOption) []Peer
- func (n *P2PNetwork) GetRoundTripper() http.RoundTripper
- func (n *P2PNetwork) OnNetworkAdvance()
- func (n *P2PNetwork) RegisterHTTPHandler(path string, handler http.Handler)
- func (n *P2PNetwork) RegisterHandlers(dispatch []TaggedMessageHandler)
- func (n *P2PNetwork) Relay(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
- func (n *P2PNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{})
- func (n *P2PNetwork) Start()
- func (n *P2PNetwork) Stop()
- func (n *P2PNetwork) SubstituteGenesisID(rawURL string) string
- type Peer
- type PeerOption
- type PhoneBookEntryRoles
- type Phonebook
- type RequestLogger
- type RequestTracker
- func (rt *RequestTracker) Accept() (conn net.Conn, err error)
- func (rt *RequestTracker) Addr() net.Addr
- func (rt *RequestTracker) Close() error
- func (rt *RequestTracker) GetRequestConnection(request *http.Request) net.Conn
- func (rt *RequestTracker) GetTrackedRequest(request *http.Request) (trackedRequest *TrackerRequest)
- func (rt *RequestTracker) Listener(listener net.Listener) net.Listener
- func (rt *RequestTracker) ServeHTTP(response http.ResponseWriter, request *http.Request)
- type Response
- type TCPInfoUnicastPeer
- type Tag
- type TaggedMessageHandler
- type Topic
- type Topics
- type TrackerRequest
- type UnicastPeer
- type WebsocketNetwork
- func (wn *WebsocketNetwork) Address() (string, bool)
- func (wn *WebsocketNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
- func (wn *WebsocketNetwork) ClearHandlers()
- func (wn *WebsocketNetwork) DeregisterMessageInterest(t protocol.Tag)
- func (wn *WebsocketNetwork) Disconnect(node Peer)
- func (wn *WebsocketNetwork) DisconnectPeers()
- func (wn *WebsocketNetwork) GetHTTPRequestConnection(request *http.Request) (conn net.Conn)
- func (wn *WebsocketNetwork) GetPeerData(peer Peer, key string) interface{}
- func (wn *WebsocketNetwork) GetPeers(options ...PeerOption) []Peer
- func (wn *WebsocketNetwork) GetRoundTripper() http.RoundTripper
- func (wn *WebsocketNetwork) NumPeers() int
- func (wn *WebsocketNetwork) OnNetworkAdvance()
- func (wn *WebsocketNetwork) PublicAddress() string
- func (wn *WebsocketNetwork) Ready() chan struct{}
- func (wn *WebsocketNetwork) RegisterHTTPHandler(path string, handler http.Handler)
- func (wn *WebsocketNetwork) RegisterHandlers(dispatch []TaggedMessageHandler)
- func (wn *WebsocketNetwork) Relay(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
- func (wn *WebsocketNetwork) RelayArray(ctx context.Context, tags []protocol.Tag, data [][]byte, wait bool, ...) error
- func (wn *WebsocketNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{})
- func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (wn *WebsocketNetwork) SetPeerData(peer Peer, key string, value interface{})
- func (wn *WebsocketNetwork) SetPrioScheme(s NetPrioScheme)
- func (wn *WebsocketNetwork) Start()
- func (wn *WebsocketNetwork) Stop()
- func (wn *WebsocketNetwork) SubstituteGenesisID(rawURL string) string
Constants ¶
const AddressHeader = "X-Algorand-Location"
AddressHeader HTTP header by which an inbound connection reports its public address
const (
ErrorKey = "Error" // used for passing an error message
)
Constant strings used as keys for topics
const GenesisHeader = "X-Algorand-Genesis"
GenesisHeader HTTP header for genesis id to make sure we're on the same chain
const GossipNetworkPath = "/v1/{genesisID}/gossip"
GossipNetworkPath is the URL path to connect to the websocket gossip node at. Contains {genesisID} param to be handled by gorilla/mux
const IdentityChallengeHeader = "X-Algorand-IdentityChallenge"
IdentityChallengeHeader is used to exchange IdentityChallenges
const InstanceNameHeader = "X-Algorand-InstanceName"
InstanceNameHeader HTTP header by which an inbound connection reports an ID to distinguish multiple local nodes.
const MaxDecompressedMessageSize = 20 * 1024 * 1024 // some large enough value
MaxDecompressedMessageSize defines a maximum decompressed data size to prevent zip bombs. This depends on MaxTxnBytesPerBlock consensus parameter and should be larger.
const MaxMessageLength = 6 * 1024 * 1024 // Currently the biggest message is VB vote bundles.
MaxMessageLength is the maximum length of a message that can be sent or received, exported to be used in the node.TestMaxSizesCorrect test
const NodeRandomHeader = "X-Algorand-NodeRandom"
NodeRandomHeader HTTP header that a node uses to make sure it's not talking to itself
const PeerFeatureProposalCompression = "ppzstd"
PeerFeatureProposalCompression is a value for PeerFeaturesHeader indicating peer supports proposal payload compression with zstd
const PeerFeaturesHeader = "X-Algorand-Peer-Features"
PeerFeaturesHeader is the HTTP header listing features
const PhoneBookEntryArchivalRole = 2
PhoneBookEntryArchivalRole used for all the archival nodes that are provided via the archive SRV record.
const PhoneBookEntryRelayRole = 1
PhoneBookEntryRelayRole used for all the relays that are provided either via the algobootstrap SRV record or via a configuration file.
const PingLength = 8
PingLength is the fixed length of ping message, exported to be used in the node.TestMaxSizesCorrect test
const PriorityChallengeHeader = "X-Algorand-PriorityChallenge"
PriorityChallengeHeader HTTP header informs a client about the challenge it should sign to increase network priority.
const ProtocolAcceptVersionHeader = "X-Algorand-Accept-Version"
ProtocolAcceptVersionHeader HTTP header for accept protocol version. Client use this to advertise supported protocol versions.
const ProtocolVersion = "2.2"
ProtocolVersion is the current version attached to the ProtocolVersionHeader header
Version history: * 1 Catchup service over websocket connections with unicast messages between peers * 2.1 Introduced topic key/data pairs and enabled services over the gossip connections * 2.2 Peer features
const ProtocolVersionHeader = "X-Algorand-Version"
ProtocolVersionHeader HTTP header for protocol version.
const TelemetryIDHeader = "X-Algorand-TelId"
TelemetryIDHeader HTTP header for telemetry-id for logging
const TooManyRequestsRetryAfterHeader = "Retry-After"
TooManyRequestsRetryAfterHeader HTTP header let the client know when to make the next connection attempt
const UserAgentHeader = "User-Agent"
UserAgentHeader is the HTTP header identify the user agent.
Variables ¶
var ErrConnectionQueueingTimeout = errors.New("rateLimitingTransport: queueing timeout")
ErrConnectionQueueingTimeout indicates that we've exceeded the time allocated for queueing the current request before the request attempt could be made.
var ErrIncomingMsgTooLarge = errors.New("read limit exceeded")
ErrIncomingMsgTooLarge is returned when an incoming message is too large
var HostColonPortPattern = regexp.MustCompile(`^[-a-zA-Z0-9.]+:\d+$`)
HostColonPortPattern matches "^[-a-zA-Z0-9.]+:\\d+$" e.g. "foo.com.:1234"
var SupportedProtocolVersions = []string{"2.2", "2.1"}
SupportedProtocolVersions contains the list of supported protocol versions by this node ( in order of preference ).
Functions ¶
func DisconnectReasonMaxSize ¶
func DisconnectReasonMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityChallengeMaxSize ¶
func IdentityChallengeMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityChallengeResponseMaxSize ¶
func IdentityChallengeResponseMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityChallengeResponseSignedMaxSize ¶
func IdentityChallengeResponseSignedMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityChallengeSignedMaxSize ¶
func IdentityChallengeSignedMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityChallengeValueMaxSize ¶
func IdentityChallengeValueMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityVerificationMessageMaxSize ¶
func IdentityVerificationMessageMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func IdentityVerificationMessageSignedMaxSize ¶
func IdentityVerificationMessageSignedMaxSize() (s int)
MaxSize returns a maximum valid message size for this message type
func MarshallMessageOfInterest ¶
MarshallMessageOfInterest generate a message of interest message body for a given set of message tags.
func MarshallMessageOfInterestMap ¶
MarshallMessageOfInterestMap generates a message of interest message body for the message tags that map to "true" in the map argument.
func MessageOfInterestMaxSize ¶
func MessageOfInterestMaxSize() int
MessageOfInterestMaxSize returns the maximum size of a MI message sent over the network by encoding all of the tags currenttly in use.
func NewIdentityChallengeScheme ¶
func NewIdentityChallengeScheme(dn string) *identityChallengePublicKeyScheme
NewIdentityChallengeScheme will create a default Identification Scheme
func NewIdentityTracker ¶
func NewIdentityTracker() *publicKeyIdentTracker
NewIdentityTracker returns a new publicKeyIdentTracker
func ParseHostOrURL ¶
ParseHostOrURL handles "host:port" or a full URL. Standard library net/url.Parse chokes on "host:port".
func ParseHostOrURLOrMultiaddr ¶
ParseHostOrURLOrMultiaddr returns an error if it could not parse the provided string as a valid "host:port", full URL, or multiaddr. If no error, it returns a host:port address, or a multiaddr.
func SetUserAgentHeader ¶
SetUserAgentHeader adds the User-Agent header to the provided heades map.
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer establish tcp-level connection with the destination
type ForwardingPolicy ¶
type ForwardingPolicy int
ForwardingPolicy is an enum indicating to whom we should send a message
const ( // Ignore - discard (don't forward) Ignore ForwardingPolicy = iota // Disconnect - disconnect from the peer that sent this message Disconnect // Broadcast - forward to everyone (except the sender) Broadcast // Respond - reply to the sender Respond )
type GossipNode ¶
type GossipNode interface { Address() (string, bool) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error Relay(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error Disconnect(badnode Peer) DisconnectPeers() // only used by testing // RegisterHTTPHandler path accepts gorilla/mux path annotations RegisterHTTPHandler(path string, handler http.Handler) // RequestConnectOutgoing asks the system to actually connect to peers. // `replace` optionally drops existing connections before making new ones. // `quit` chan allows cancellation. TODO: use `context` RequestConnectOutgoing(replace bool, quit <-chan struct{}) // Get a list of Peers we could potentially send a direct message to. GetPeers(options ...PeerOption) []Peer // Start threads, listen on sockets. Start() // Close sockets. Stop threads. Stop() // RegisterHandlers adds to the set of given message handlers. RegisterHandlers(dispatch []TaggedMessageHandler) // ClearHandlers deregisters all the existing message handlers. ClearHandlers() // GetRoundTripper returns a Transport that would limit the number of outgoing connections. GetRoundTripper() http.RoundTripper // OnNetworkAdvance notifies the network library that the agreement protocol was able to make a notable progress. // this is the only indication that we have that we haven't formed a clique, where all incoming messages // arrive very quickly, but might be missing some votes. The usage of this call is expected to have similar // characteristics as with a watchdog timer. OnNetworkAdvance() // GetHTTPRequestConnection returns the underlying connection for the given request. Note that the request must be the same // request that was provided to the http handler ( or provide a fallback Context() to that ) GetHTTPRequestConnection(request *http.Request) (conn net.Conn) // SubstituteGenesisID substitutes the "{genesisID}" with their network-specific genesisID. SubstituteGenesisID(rawURL string) string // contains filtered or unexported methods }
GossipNode represents a node in the gossip network
func NewWebsocketGossipNode ¶
func NewWebsocketGossipNode(log logging.Logger, config config.Local, phonebookAddresses []string, genesisID string, networkID protocol.NetworkID) (gn GossipNode, err error)
NewWebsocketGossipNode constructs a websocket network node and returns it as a GossipNode interface implementation
type HTTPPeer ¶
HTTPPeer is what the opaque Peer might be. If you get an opaque Peer handle from a GossipNode, maybe try a .(HTTPPeer) type assertion on it.
type HandlerFunc ¶
type HandlerFunc func(message IncomingMessage) OutgoingMessage
HandlerFunc represents an implemenation of the MessageHandler interface
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(message IncomingMessage) OutgoingMessage
Handle implements MessageHandler.Handle, calling the handler with the IncomingKessage and returning the OutgoingMessage
type IPAddressable ¶
IPAddressable is addressable with either IPv4 or IPv6 address
type IncomingMessage ¶
type IncomingMessage struct { Sender Peer Tag Tag Data []byte Err error Net GossipNode // Received is time.Time.UnixNano() Received int64 // contains filtered or unexported fields }
IncomingMessage represents a message arriving from some peer in our p2p network
type LimitedReaderSlurper ¶
type LimitedReaderSlurper struct {
// contains filtered or unexported fields
}
LimitedReaderSlurper collects bytes from an io.Reader, but stops if a limit is reached.
func MakeLimitedReaderSlurper ¶
func MakeLimitedReaderSlurper(baseAllocation, maxAllocation uint64) *LimitedReaderSlurper
MakeLimitedReaderSlurper creates a LimitedReaderSlurper instance with the provided base and max memory allocations.
func (*LimitedReaderSlurper) Bytes ¶
func (s *LimitedReaderSlurper) Bytes() []byte
Bytes returns a copy of all the collected data
func (*LimitedReaderSlurper) Read ¶
func (s *LimitedReaderSlurper) Read(reader io.Reader) error
Read does repeated Read()s on the io.Reader until it gets io.EOF. Returns underlying error or ErrIncomingMsgTooLarge if limit reached. Returns a nil error if the underlying io.Reader returned io.EOF.
func (*LimitedReaderSlurper) Reset ¶
func (s *LimitedReaderSlurper) Reset(n uint64)
Reset clears the buffered data and sets a limit for the upcoming message
func (*LimitedReaderSlurper) Size ¶
func (s *LimitedReaderSlurper) Size() (size uint64)
Size returs the current total size of contained chunks read from io.Reader
type MessageHandler ¶
type MessageHandler interface {
Handle(message IncomingMessage) OutgoingMessage
}
MessageHandler takes a IncomingMessage (e.g., vote, transaction), processes it, and returns what (if anything) to send to the network in response. The ForwardingPolicy field of the returned OutgoingMessage indicates whether to reply directly to the sender (unicast), propagate to everyone except the sender (broadcast), or do nothing (ignore).
type Multiplexer ¶
type Multiplexer struct {
// contains filtered or unexported fields
}
Multiplexer is a message handler that sorts incoming messages by Tag and passes them along to the relevant message handler for that type of message.
func MakeMultiplexer ¶
func MakeMultiplexer() *Multiplexer
MakeMultiplexer creates an empty Multiplexer
func (*Multiplexer) ClearHandlers ¶
func (m *Multiplexer) ClearHandlers(excludeTags []Tag)
ClearHandlers deregisters all the existing message handlers other than the one provided in the excludeTags list
func (*Multiplexer) Handle ¶
func (m *Multiplexer) Handle(msg IncomingMessage) OutgoingMessage
Handle is the "input" side of the multiplexer. It dispatches the message to the previously defined handler.
func (*Multiplexer) RegisterHandlers ¶
func (m *Multiplexer) RegisterHandlers(dispatch []TaggedMessageHandler)
RegisterHandlers registers the set of given message handlers.
type NetPrioScheme ¶
type NetPrioScheme interface { NewPrioChallenge() string MakePrioResponse(challenge string) []byte VerifyPrioResponse(challenge string, response []byte) (basics.Address, error) GetPrioWeight(addr basics.Address) uint64 }
NetPrioScheme is an implementation of network connection priorities based on a challenge-response protocol.
type NodeInfo ¶
type NodeInfo interface { // IsParticipating returns true if this node has stake and may vote on blocks or propose blocks. IsParticipating() bool }
NodeInfo helps the network get information about the node it is running on
type OutgoingMessage ¶
type OutgoingMessage struct { Action ForwardingPolicy Tag Tag Payload []byte Topics Topics // OnRelease is a function called when outgoing message, resulting from this incoming message, is released // either by being sent or discarded. OnRelease func() // contains filtered or unexported fields }
OutgoingMessage represents a message we want to send.
func Propagate ¶
func Propagate(msg IncomingMessage) OutgoingMessage
Propagate is a convenience function to save typing in the common case of a message handler telling us to propagate an incoming message "return network.Propagate(msg)" instead of "return network.OutgoingMsg{network.Broadcast, msg.Tag, msg.Data}"
type P2PNetwork ¶
type P2PNetwork struct {
// contains filtered or unexported fields
}
P2PNetwork implements the GossipNode interface
func NewP2PNetwork ¶
func NewP2PNetwork(log logging.Logger, cfg config.Local, datadir string, phonebookAddresses []string, genesisID string, networkID protocol.NetworkID) (*P2PNetwork, error)
NewP2PNetwork returns an instance of GossipNode that uses the p2p.Service
func (*P2PNetwork) Address ¶
func (n *P2PNetwork) Address() (string, bool)
Address returns a string and whether that is a 'final' address or guessed.
func (*P2PNetwork) Broadcast ¶
func (n *P2PNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
Broadcast sends a message.
func (*P2PNetwork) ClearHandlers ¶
func (n *P2PNetwork) ClearHandlers()
ClearHandlers deregisters all the existing message handlers.
func (*P2PNetwork) Disconnect ¶
func (n *P2PNetwork) Disconnect(badnode Peer)
Disconnect from a peer, probably due to protocol errors.
func (*P2PNetwork) DisconnectPeers ¶
func (n *P2PNetwork) DisconnectPeers()
DisconnectPeers is used by testing
func (*P2PNetwork) GetGenesisID ¶
func (n *P2PNetwork) GetGenesisID() string
GetGenesisID implements GossipNode
func (*P2PNetwork) GetHTTPRequestConnection ¶
func (n *P2PNetwork) GetHTTPRequestConnection(request *http.Request) (conn net.Conn)
GetHTTPRequestConnection returns the underlying connection for the given request. Note that the request must be the same request that was provided to the http handler ( or provide a fallback Context() to that )
func (*P2PNetwork) GetPeers ¶
func (n *P2PNetwork) GetPeers(options ...PeerOption) []Peer
GetPeers returns a list of Peers we could potentially send a direct message to.
func (*P2PNetwork) GetRoundTripper ¶
func (n *P2PNetwork) GetRoundTripper() http.RoundTripper
GetRoundTripper returns a Transport that would limit the number of outgoing connections.
func (*P2PNetwork) OnNetworkAdvance ¶
func (n *P2PNetwork) OnNetworkAdvance()
OnNetworkAdvance notifies the network library that the agreement protocol was able to make a notable progress. this is the only indication that we have that we haven't formed a clique, where all incoming messages arrive very quickly, but might be missing some votes. The usage of this call is expected to have similar characteristics as with a watchdog timer.
func (*P2PNetwork) RegisterHTTPHandler ¶
func (n *P2PNetwork) RegisterHTTPHandler(path string, handler http.Handler)
RegisterHTTPHandler path accepts gorilla/mux path annotations
func (*P2PNetwork) RegisterHandlers ¶
func (n *P2PNetwork) RegisterHandlers(dispatch []TaggedMessageHandler)
RegisterHandlers adds to the set of given message handlers.
func (*P2PNetwork) Relay ¶
func (n *P2PNetwork) Relay(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
Relay message
func (*P2PNetwork) RequestConnectOutgoing ¶
func (n *P2PNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{})
RequestConnectOutgoing asks the system to actually connect to peers. `replace` optionally drops existing connections before making new ones. `quit` chan allows cancellation.
func (*P2PNetwork) SubstituteGenesisID ¶
func (n *P2PNetwork) SubstituteGenesisID(rawURL string) string
SubstituteGenesisID substitutes the "{genesisID}" with their network-specific genesisID.
type PeerOption ¶
type PeerOption int
PeerOption allows users to specify a subset of peers to query
const ( // PeersConnectedOut specifies all peers with outgoing connections PeersConnectedOut PeerOption = iota // PeersConnectedIn specifies all peers with inbound connections PeersConnectedIn PeerOption = iota // PeersPhonebookRelays specifies all relays in the phonebook PeersPhonebookRelays PeerOption = iota // PeersPhonebookArchivalNodes specifies all archival nodes (relay or p2p) PeersPhonebookArchivalNodes PeerOption = iota )
type PhoneBookEntryRoles ¶
type PhoneBookEntryRoles int
PhoneBookEntryRoles defines the roles that a single entry on the phonebook can take. currently, we have two roles : relay role and archival role, which are mutually exclusive.
type Phonebook ¶
type Phonebook interface { // GetAddresses(N) returns up to N addresses, but may return fewer GetAddresses(n int, role PhoneBookEntryRoles) []string // UpdateRetryAfter updates the retry-after field for the entries matching the given address UpdateRetryAfter(addr string, retryAfter time.Time) // GetConnectionWaitTime will calculate and return the wait // time to prevent exceeding connectionsRateLimitingCount. // The connection should be established when the waitTime is 0. // It will register a provisional next connection time when the waitTime is 0. // The provisional time should be updated after the connection with UpdateConnectionTime GetConnectionWaitTime(addr string) (addrInPhonebook bool, waitTime time.Duration, provisionalTime time.Time) // UpdateConnectionTime will update the provisional connection time. // Returns true of the addr was in the phonebook UpdateConnectionTime(addr string, provisionalTime time.Time) bool // ReplacePeerList merges a set of addresses with that passed in for networkName // new entries in dnsAddresses are being added // existing items that aren't included in dnsAddresses are being removed // matching entries don't change ReplacePeerList(dnsAddresses []string, networkName string, role PhoneBookEntryRoles) // AddPersistentPeers stores addresses of peers which are persistent. // i.e. they won't be replaced by ReplacePeerList calls AddPersistentPeers(dnsAddresses []string, networkName string, role PhoneBookEntryRoles) }
Phonebook stores or looks up addresses of nodes we might contact
type RequestLogger ¶
type RequestLogger struct {
// contains filtered or unexported fields
}
RequestLogger is a middleware helps logging all the incoming http requests. The intended use is to place it at the bottom of the http processing. It will capture the status codes set by the upstream handlers and write the request info/response to the logger.
func (*RequestLogger) ServeHTTP ¶
func (rl *RequestLogger) ServeHTTP(writer http.ResponseWriter, request *http.Request)
this is the http entry point for the request logger.
func (*RequestLogger) SetStatusCode ¶
func (rl *RequestLogger) SetStatusCode(writer http.ResponseWriter, statusCode int)
SetStatusCode sets the status code of a given response writer without writing it to the underlaying writer object.
type RequestTracker ¶
type RequestTracker struct {
// contains filtered or unexported fields
}
RequestTracker tracks the incoming request connections
func (*RequestTracker) Accept ¶
func (rt *RequestTracker) Accept() (conn net.Conn, err error)
Accept waits for and returns the next connection to the listener.
func (*RequestTracker) Addr ¶
func (rt *RequestTracker) Addr() net.Addr
Addr returns the listener's network address.
func (*RequestTracker) Close ¶
func (rt *RequestTracker) Close() error
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
func (*RequestTracker) GetRequestConnection ¶
func (rt *RequestTracker) GetRequestConnection(request *http.Request) net.Conn
GetRequestConnection return the underlying connection for the given request
func (*RequestTracker) GetTrackedRequest ¶
func (rt *RequestTracker) GetTrackedRequest(request *http.Request) (trackedRequest *TrackerRequest)
GetTrackedRequest return the tracked request
func (*RequestTracker) Listener ¶
func (rt *RequestTracker) Listener(listener net.Listener) net.Listener
Listener initialize the underlaying listener, and return the request tracker wrapping listener
func (*RequestTracker) ServeHTTP ¶
func (rt *RequestTracker) ServeHTTP(response http.ResponseWriter, request *http.Request)
type Response ¶
type Response struct {
Topics Topics
}
Response is the structure holding the response from the server
type TCPInfoUnicastPeer ¶
type TCPInfoUnicastPeer interface { UnicastPeer GetUnderlyingConnTCPInfo() (*util.TCPInfo, error) }
TCPInfoUnicastPeer exposes information about the underlying connection if available on the platform
type TaggedMessageHandler ¶
type TaggedMessageHandler struct { Tag MessageHandler }
TaggedMessageHandler receives one type of broadcast messages
type Topic ¶
type Topic struct {
// contains filtered or unexported fields
}
Topic is a key-value pair
func MakeNonceTopic ¶
MakeNonceTopic returns a topic with the nonce as the data exported for testing purposes
type Topics ¶
type Topics []Topic
Topics is an array of type Topic The maximum number of topics allowed is 32 Each topic key can be 64 characters long and cannot be size 0
func UnmarshallTopics ¶
UnmarshallTopics unmarshalls the topics from the byte array
func (Topics) MarshallTopics ¶
MarshallTopics serializes the topics into a byte array
type TrackerRequest ¶
type TrackerRequest struct {
// contains filtered or unexported fields
}
TrackerRequest hold the tracking data associated with a single request. It supposed by an upstream http.Handler called before the wsNetwork's ServeHTTP and wsNetwork's Listener (see Accept() method)
type UnicastPeer ¶
type UnicastPeer interface { GetAddress() string // Unicast sends the given bytes to this specific peer. Does not wait for message to be sent. Unicast(ctx context.Context, data []byte, tag protocol.Tag) error // Version returns the matching version from network.SupportedProtocolVersions Version() string Request(ctx context.Context, tag Tag, topics Topics) (resp *Response, e error) Respond(ctx context.Context, reqMsg IncomingMessage, outMsg OutgoingMessage) (e error) }
UnicastPeer is another possible interface for the opaque Peer. It is possible that we can only initiate a connection to a peer over websockets.
type WebsocketNetwork ¶
type WebsocketNetwork struct { GenesisID string NetworkID protocol.NetworkID RandomID string // contains filtered or unexported fields }
WebsocketNetwork implements GossipNode
func NewWebsocketNetwork ¶
func NewWebsocketNetwork(log logging.Logger, config config.Local, phonebookAddresses []string, genesisID string, networkID protocol.NetworkID, nodeInfo NodeInfo) (wn *WebsocketNetwork, err error)
NewWebsocketNetwork constructor for websockets based gossip network
func (*WebsocketNetwork) Address ¶
func (wn *WebsocketNetwork) Address() (string, bool)
Address returns a string and whether that is a 'final' address or guessed. Part of GossipNode interface
func (*WebsocketNetwork) Broadcast ¶
func (wn *WebsocketNetwork) Broadcast(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
Broadcast sends a message. If except is not nil then we will not send it to that neighboring Peer. if wait is true then the call blocks until the packet has actually been sent to all neighbors.
func (*WebsocketNetwork) ClearHandlers ¶
func (wn *WebsocketNetwork) ClearHandlers()
ClearHandlers deregisters all the existing message handlers.
func (*WebsocketNetwork) DeregisterMessageInterest ¶
func (wn *WebsocketNetwork) DeregisterMessageInterest(t protocol.Tag)
DeregisterMessageInterest will tell peers to no longer send us traffic with a protocol Tag
func (*WebsocketNetwork) Disconnect ¶
func (wn *WebsocketNetwork) Disconnect(node Peer)
Disconnect from a peer, probably due to protocol errors.
func (*WebsocketNetwork) DisconnectPeers ¶
func (wn *WebsocketNetwork) DisconnectPeers()
DisconnectPeers shuts down all connections
func (*WebsocketNetwork) GetHTTPRequestConnection ¶
func (wn *WebsocketNetwork) GetHTTPRequestConnection(request *http.Request) (conn net.Conn)
GetHTTPRequestConnection returns the underlying connection for the given request. Note that the request must be the same request that was provided to the http handler ( or provide a fallback Context() to that ) if the provided request has no associated connection, it returns nil. ( this should not happen for any http request that was registered by WebsocketNetwork )
func (*WebsocketNetwork) GetPeerData ¶
func (wn *WebsocketNetwork) GetPeerData(peer Peer, key string) interface{}
GetPeerData returns the peer data associated with a particular key.
func (*WebsocketNetwork) GetPeers ¶
func (wn *WebsocketNetwork) GetPeers(options ...PeerOption) []Peer
GetPeers returns a snapshot of our Peer list, according to the specified options. Peers may be duplicated and refer to the same underlying node.
func (*WebsocketNetwork) GetRoundTripper ¶
func (wn *WebsocketNetwork) GetRoundTripper() http.RoundTripper
GetRoundTripper returns an http.Transport that limits the number of connection to comply with connectionsRateLimitingCount.
func (*WebsocketNetwork) NumPeers ¶
func (wn *WebsocketNetwork) NumPeers() int
NumPeers returns number of peers we connect to (all peers incoming and outbound).
func (*WebsocketNetwork) OnNetworkAdvance ¶
func (wn *WebsocketNetwork) OnNetworkAdvance()
OnNetworkAdvance notifies the network library that the agreement protocol was able to make a notable progress. this is the only indication that we have that we haven't formed a clique, where all incoming messages arrive very quickly, but might be missing some votes. The usage of this call is expected to have similar characteristics as with a watchdog timer.
func (*WebsocketNetwork) PublicAddress ¶
func (wn *WebsocketNetwork) PublicAddress() string
PublicAddress what we tell other nodes to connect to. Might be different than our locally perceived network address due to NAT/etc. Returns config "PublicAddress" if available, otherwise local addr.
func (*WebsocketNetwork) Ready ¶
func (wn *WebsocketNetwork) Ready() chan struct{}
Ready returns a chan that will be closed when we have a minimum number of peer connections active
func (*WebsocketNetwork) RegisterHTTPHandler ¶
func (wn *WebsocketNetwork) RegisterHTTPHandler(path string, handler http.Handler)
RegisterHTTPHandler path accepts gorilla/mux path annotations
func (*WebsocketNetwork) RegisterHandlers ¶
func (wn *WebsocketNetwork) RegisterHandlers(dispatch []TaggedMessageHandler)
RegisterHandlers registers the set of given message handlers.
func (*WebsocketNetwork) Relay ¶
func (wn *WebsocketNetwork) Relay(ctx context.Context, tag protocol.Tag, data []byte, wait bool, except Peer) error
Relay message
func (*WebsocketNetwork) RelayArray ¶
func (wn *WebsocketNetwork) RelayArray(ctx context.Context, tags []protocol.Tag, data [][]byte, wait bool, except Peer) error
RelayArray relays array of messages
func (*WebsocketNetwork) RequestConnectOutgoing ¶
func (wn *WebsocketNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{})
RequestConnectOutgoing tries to actually do the connect to new peers. `replace` drop all connections first and find new peers.
func (*WebsocketNetwork) ServeHTTP ¶
func (wn *WebsocketNetwork) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServerHTTP handles the gossip network functions over websockets
func (*WebsocketNetwork) SetPeerData ¶
func (wn *WebsocketNetwork) SetPeerData(peer Peer, key string, value interface{})
SetPeerData sets the peer data associated with a particular key.
func (*WebsocketNetwork) SetPrioScheme ¶
func (wn *WebsocketNetwork) SetPrioScheme(s NetPrioScheme)
SetPrioScheme specifies the network priority scheme for a network node
func (*WebsocketNetwork) Start ¶
func (wn *WebsocketNetwork) Start()
Start makes network connections and threads
func (*WebsocketNetwork) Stop ¶
func (wn *WebsocketNetwork) Stop()
Stop closes network connections and stops threads. Stop blocks until all activity on this node is done.
func (*WebsocketNetwork) SubstituteGenesisID ¶
func (wn *WebsocketNetwork) SubstituteGenesisID(rawURL string) string
SubstituteGenesisID substitutes the "{genesisID}" with their network-specific genesisID.
Source Files ¶
- addr.go
- connPerfMon.go
- dialer.go
- gossipNode.go
- limited_reader_slurper.go
- messageFilter.go
- msgCompressor.go
- msgOfInterest.go
- msgp_gen.go
- multiplexer.go
- netidentity.go
- netprio.go
- p2pNetwork.go
- p2pPeer.go
- peersheap.go
- phonebook.go
- rateLimitingTransport.go
- requestLogger.go
- requestTracker.go
- topics.go
- wsNetwork.go
- wsPeer.go