Documentation ¶
Index ¶
- Constants
- Variables
- func IP2Location(addr string) (uint32, error)
- func IP2LocationQuick(addr string) uint32
- func StringToUint32(input string) uint32
- func WebScanner(url string, f func(line string)) error
- type Configuration
- type Dialer
- type Endpoint
- type Handshake
- type Info
- type LimitedListener
- type MetricsReadWriter
- type Network
- func (n *Network) Ban(hash string)
- func (n *Network) BlockingSend(p *Parcel)
- func (n *Network) Disconnect(hash string)
- func (n *Network) GetInfo() Info
- func (n *Network) GetPeerMetrics() map[string]PeerMetrics
- func (n *Network) Reader() <-chan *Parcel
- func (n *Network) Rounds() int
- func (n *Network) Run() error
- func (n *Network) Send(p *Parcel)
- func (n *Network) SetMetricsHook(f func(pm map[string]PeerMetrics))
- func (n *Network) SetSpecial(raw string)
- func (n *Network) Stop() error
- func (n *Network) Total() int
- type NetworkID
- type Parcel
- type ParcelChannel
- type ParcelType
- type Peer
- type PeerCache
- type PeerHashCache
- type PeerMetrics
- type PeerStore
- func (ps *PeerStore) Add(p *Peer) error
- func (ps *PeerStore) Connected(ep Endpoint) bool
- func (ps *PeerStore) Connections(addr string) int
- func (ps *PeerStore) Count(addr string) int
- func (ps *PeerStore) Get(hash string) *Peer
- func (ps *PeerStore) Incoming() int
- func (ps *PeerStore) Outgoing() int
- func (ps *PeerStore) Remove(p *Peer)
- func (ps *PeerStore) Slice() []*Peer
- func (ps *PeerStore) Total() int
- type Prometheus
- type Protocol
- type ProtocolV10
- func (v10 *ProtocolV10) MakePeerShare(share []Endpoint) ([]byte, error)
- func (v10 *ProtocolV10) ParsePeerShare(payload []byte) ([]Endpoint, error)
- func (v10 *ProtocolV10) ReadHandshake() (*Handshake, error)
- func (v10 *ProtocolV10) Receive() (*Parcel, error)
- func (v10 *ProtocolV10) Send(p *Parcel) error
- func (v10 *ProtocolV10) SendHandshake(h *Handshake) error
- func (v10 *ProtocolV10) String() string
- func (v10 *ProtocolV10) Version() uint16
- type ProtocolV11
- func (v11 *ProtocolV11) MakePeerShare(ps []Endpoint) ([]byte, error)
- func (v11 *ProtocolV11) ParsePeerShare(payload []byte) ([]Endpoint, error)
- func (v11 *ProtocolV11) ReadHandshake() (*Handshake, error)
- func (v11 *ProtocolV11) Receive() (*Parcel, error)
- func (v11 *ProtocolV11) Send(p *Parcel) error
- func (v11 *ProtocolV11) SendHandshake(hs *Handshake) error
- func (v11 *ProtocolV11) String() string
- func (v11 *ProtocolV11) Version() uint16
- type ProtocolV9
- func (v9 *ProtocolV9) MakePeerShare(ps []Endpoint) ([]byte, error)
- func (v9 *ProtocolV9) ParsePeerShare(payload []byte) ([]Endpoint, error)
- func (v9 *ProtocolV9) ReadHandshake() (*Handshake, error)
- func (v9 *ProtocolV9) Receive() (*Parcel, error)
- func (v9 *ProtocolV9) Send(p *Parcel) error
- func (v9 *ProtocolV9) SendHandshake(h *Handshake) error
- func (v9 *ProtocolV9) String() string
- func (v9 *ProtocolV9) Version() uint16
- type ReadWriteCollector
- type StatsCollector
- type V10Msg
- type V10Share
- type V11Endpoint
- func (*V11Endpoint) Descriptor() ([]byte, []int)
- func (m *V11Endpoint) GetHost() string
- func (m *V11Endpoint) GetPort() string
- func (m *V11Endpoint) Marshal() (dAtA []byte, err error)
- func (m *V11Endpoint) MarshalTo(dAtA []byte) (int, error)
- func (m *V11Endpoint) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*V11Endpoint) ProtoMessage()
- func (m *V11Endpoint) Reset()
- func (m *V11Endpoint) Size() (n int)
- func (m *V11Endpoint) String() string
- func (m *V11Endpoint) Unmarshal(dAtA []byte) error
- func (m *V11Endpoint) XXX_DiscardUnknown()
- func (m *V11Endpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *V11Endpoint) XXX_Merge(src proto.Message)
- func (m *V11Endpoint) XXX_Size() int
- func (m *V11Endpoint) XXX_Unmarshal(b []byte) error
- type V11Handshake
- func (*V11Handshake) Descriptor() ([]byte, []int)
- func (m *V11Handshake) GetAlternatives() []*V11Endpoint
- func (m *V11Handshake) GetListenPort() string
- func (m *V11Handshake) GetLoopback() uint64
- func (m *V11Handshake) GetNetwork() uint32
- func (m *V11Handshake) GetNodeID() uint32
- func (m *V11Handshake) GetType() uint32
- func (m *V11Handshake) GetVersion() uint32
- func (m *V11Handshake) Marshal() (dAtA []byte, err error)
- func (m *V11Handshake) MarshalTo(dAtA []byte) (int, error)
- func (m *V11Handshake) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*V11Handshake) ProtoMessage()
- func (m *V11Handshake) Reset()
- func (m *V11Handshake) Size() (n int)
- func (m *V11Handshake) String() string
- func (m *V11Handshake) Unmarshal(dAtA []byte) error
- func (m *V11Handshake) XXX_DiscardUnknown()
- func (m *V11Handshake) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *V11Handshake) XXX_Merge(src proto.Message)
- func (m *V11Handshake) XXX_Size() int
- func (m *V11Handshake) XXX_Unmarshal(b []byte) error
- type V11Msg
- func (*V11Msg) Descriptor() ([]byte, []int)
- func (m *V11Msg) GetPayload() []byte
- func (m *V11Msg) GetType() uint32
- func (m *V11Msg) Marshal() (dAtA []byte, err error)
- func (m *V11Msg) MarshalTo(dAtA []byte) (int, error)
- func (m *V11Msg) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*V11Msg) ProtoMessage()
- func (m *V11Msg) Reset()
- func (m *V11Msg) Size() (n int)
- func (m *V11Msg) String() string
- func (m *V11Msg) Unmarshal(dAtA []byte) error
- func (m *V11Msg) XXX_DiscardUnknown()
- func (m *V11Msg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *V11Msg) XXX_Merge(src proto.Message)
- func (m *V11Msg) XXX_Size() int
- func (m *V11Msg) XXX_Unmarshal(b []byte) error
- type V11Share
- func (*V11Share) Descriptor() ([]byte, []int)
- func (m *V11Share) GetShare() []*V11Endpoint
- func (m *V11Share) Marshal() (dAtA []byte, err error)
- func (m *V11Share) MarshalTo(dAtA []byte) (int, error)
- func (m *V11Share) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*V11Share) ProtoMessage()
- func (m *V11Share) Reset()
- func (m *V11Share) Size() (n int)
- func (m *V11Share) String() string
- func (m *V11Share) Unmarshal(dAtA []byte) error
- func (m *V11Share) XXX_DiscardUnknown()
- func (m *V11Share) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *V11Share) XXX_Merge(src proto.Message)
- func (m *V11Share) XXX_Size() int
- func (m *V11Share) XXX_Unmarshal(b []byte) error
- type V9Header
- type V9Msg
- type V9Share
Constants ¶
const ( // Broadcast sends a parcel to multiple peers (randomly selected based on fanout and special peers) Broadcast = "<BROADCAST>" // FullBroadcast sends a parcel to all peers FullBroadcast = "<FULLBORADCAST>" // RandomPeer sends a parcel to one randomly selected peer RandomPeer = "<RANDOMPEER>" )
const V11MaxParcelSize = 134217728
V11MaxParcelSize limits the amount of ram allocated for a parcel to 128 MiB
Variables ¶
var ( ErrInvalidLengthProtocolV11 = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowProtocolV11 = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupProtocolV11 = fmt.Errorf("proto: unexpected end of group") )
var V11Signature = []byte{0x70, 0x62, 0x75, 0x66} // ascii for "pbuf"
V11Signature is the 4-byte sequence that indicates the remote connection wants to use V11
Functions ¶
func IP2Location ¶
IP2Location converts an ip address to a uint32
If the address is a hostmask, it attempts to resolve the address first
func IP2LocationQuick ¶
IP2LocationQuick converts an ip address to a uint32 without a hostmask lookup
func StringToUint32 ¶
StringToUint32 hashes the input to generate a deterministic number representation
func WebScanner ¶
WebScanner is a wrapper that applies the closure f to the response body
Types ¶
type Configuration ¶
type Configuration struct { // Network is the NetworkID of the network to use, eg. MainNet, TestNet, etc Network NetworkID // NodeID is this node's id NodeID uint32 // NodeName is the internal name of the node NodeName string // === Peer Management Settings === // PeerRequestInterval dictates how often neighbors should be asked for an // updated peer list PeerRequestInterval time.Duration // PeerReseedInterval dictates how often the seed file should be accessed // to check for changes PeerReseedInterval time.Duration // PeerIPLimit specifies the maximum amount of peers to accept from a single // ip address // 0 for unlimited PeerIPLimitIncoming uint PeerIPLimitOutgoing uint // Special is a list of special peers, separated by comma. If no port is specified, the entire // ip is considered special Special string // PeerCacheFile is the filepath to the file to save peers. It is persisted in every CAT round PeerCacheFile string // PeerCacheAge is the maximum age of the peer file to try and bootstrap peers from PeerCacheAge time.Duration PeerShareAmount uint PeerShareTimeout time.Duration // CAT Settings // How often to do cat rounds RoundTime time.Duration // Desired amount of peers TargetPeers uint // Hard cap of connections MaxPeers uint // Amount of peers to drop down to DropTo uint // Reseed if there are fewer than this peers MinReseed uint MaxIncoming uint // maximum inbound connections, 0 <= MaxIncoming <= MaxPeers // Fanout controls how many random peers are selected for propagating messages // Higher values increase fault tolerance but also increase network congestion Fanout uint // SeedURL is the URL of the remote seed file SeedURL string // URL to a source of peer info // BindIP is the ip address to bind to for listening and connecting // // leave blank to bind to all BindIP string // ListenPort is the port to listen to incoming tcp connections on ListenPort string // ListenLimit is the lockout period of accepting connections from a single // ip after having a successful connection from that ip ListenLimit time.Duration // PingInterval dictates the maximum amount of time a connection can be // silent (no writes) before sending a Ping. // Values under one second are normalized to one second. PingInterval time.Duration // RedialInterval dictates how long to wait between connection attempts RedialInterval time.Duration // ManualBan is the duration to ban an address for when banned manually ManualBan time.Duration // HandshakeDeadline is the maximum acceptable time for an incoming conneciton // to send the first parcel after connecting HandshakeTimeout time.Duration DialTimeout time.Duration // ReadDeadline is the maximum acceptable time to read a single parcel // if a connection takes longer, it is disconnected ReadDeadline time.Duration // WriteDeadline is the maximum acceptable time to send a single parcel // if a connection takes longer, it is disconnected WriteDeadline time.Duration ProtocolVersion uint16 // ProtocolVersionMinimum is the earliest version this package supports ProtocolVersionMinimum uint16 // ChannelCapacity dictates how large each peer's send channel is. // Should be large enough to accomodate bursts of traffic. ChannelCapacity uint EnablePrometheus bool // Enable prometheus logging. Disable if you run multiple instances // PeerResend turns on tracking of application parcels to prevent sending the same // application parcel to peers who already sent it to us PeerResendFilter bool // PeerResendBuckets controls the number of buckets to keep. The coverage of Resend messages // equals Buckets * time.Duration PeerResendBuckets int // PeerResendInterval controls how wide each bucket is PeerResendInterval time.Duration }
Configuration defines the behavior of the gossip network protocol
func DefaultP2PConfiguration ¶
func DefaultP2PConfiguration() (c Configuration)
DefaultP2PConfiguration returns a network configuration with base values These should be overwritten with command line and config parameters
func (Configuration) Check ¶
func (c Configuration) Check() error
Check will return an error if there is a configuration value set in a way that would prevent the normal functions of a node
func (*Configuration) Sanitize ¶
func (c *Configuration) Sanitize()
Sanitize automatically adjusts some variables that are dependent on others
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer is a construct to throttle dialing and limit by attempts
type Endpoint ¶
func NewEndpoint ¶
NewEndpoint creates an Endpoint struct from a given ip and port, throws error if ip could not be resolved
func ParseEndpoint ¶
ParseEndpoint takes input in the form of "ip:port" and returns its IP
type Handshake ¶
type Handshake struct { Network NetworkID Version uint16 Type ParcelType NodeID uint32 ListenPort string Loopback uint64 Alternatives []Endpoint }
Handshake is the protocol independent data that is required to authenticate a peer.
func (*Handshake) Valid ¶
func (h *Handshake) Valid(conf *Configuration) error
Valid checks the Handshake's data against a configuration. Loopback is checked outside of this function.
type Info ¶
type Info struct { Peers int // number of peers connected Receiving float64 // download rate in Messages/s Sending float64 // upload rate in Messages/s Download float64 // download rate in Bytes/s Upload float64 // upload rate in Bytes/s Dropped uint64 // number of parcels dropped due to low speed }
Info holds the data that can be queried from the Network
type LimitedListener ¶
type LimitedListener struct {
// contains filtered or unexported fields
}
LimitedListener will block multiple connection attempts from a single ip within a specific timeframe
func NewLimitedListener ¶
func NewLimitedListener(address string, limit time.Duration) (*LimitedListener, error)
NewLimitedListener initializes a new listener for the specified address (host:port) throttling incoming connections
func (*LimitedListener) Accept ¶
func (ll *LimitedListener) Accept() (net.Conn, error)
Accept accepts a connection if no other connection attempt from that ip has been made in the specified time frame
func (*LimitedListener) Addr ¶
func (ll *LimitedListener) Addr() net.Addr
Addr returns the address the listener is listening to
func (*LimitedListener) Close ¶
func (ll *LimitedListener) Close()
Close closes the associated net.Listener
type MetricsReadWriter ¶
type MetricsReadWriter struct {
// contains filtered or unexported fields
}
MetricsReadWriter is a wrapper for net.Conn that allows the package to observe the actual amount of bytes passing through it
func NewMetricsReadWriter ¶
func NewMetricsReadWriter(rw io.ReadWriter) *MetricsReadWriter
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is the main access point for outside applications.
ToNetwork is the channel over which to send parcels to the network layer ¶
FromNetwork is the channel that gets filled with parcels arriving from the network layer
func NewNetwork ¶
func NewNetwork(conf Configuration) (*Network, error)
NewNetwork initializes a new network with the given configuration. The passed Configuration is copied and cannot be modified afterwards. Does not start the network automatically.
func (*Network) Ban ¶
Ban removes a peer as well as any other peer from that address and prevents any connection being established for the amount of time set in the configuration (default one week)
func (*Network) BlockingSend ¶
BlockingSend accepts a parcel and sends it to the appropriate parties. This function blocks after the queue fills up.
func (*Network) Disconnect ¶
Disconnect severs connection for a specific peer. They are free to connect again afterward
func (*Network) GetPeerMetrics ¶
func (n *Network) GetPeerMetrics() map[string]PeerMetrics
func (*Network) Reader ¶
Reader returns a read-only channel containing application parcels arriving from the network.
func (*Network) Run ¶
Run starts the network. Listens to incoming connections on the specified port and connects to other peers
func (*Network) Send ¶
Send accepts a parcel and sends it to the appropriate parties. This function is non-blocking. If the network goes down, older messages are dropped first.
func (*Network) SetMetricsHook ¶
func (n *Network) SetMetricsHook(f func(pm map[string]PeerMetrics))
SetMetricsHook allows you to read peer metrics. Gets called approximately once a second and transfers the metrics of all CONNECTED peers in the format "identifying hash" -> p2p.PeerMetrics
func (*Network) SetSpecial ¶
SetSpecial takes a set of ip addresses that should be treated as special. Network will always attempt to have a connection to a special peer. Format is a single line of ip addresses and ports, separated by semicolon, eg "127.0.0.1:8088;8.0.8.8:8088;192.168.0.1:8110"
type NetworkID ¶
type NetworkID uint32
NetworkID represents the P2P network we are participating in (eg: test, nmain, etc.)
const ( MainNet NetworkID = 0xfeedbeef TestNet NetworkID = 0xdeadbeef LocalNet NetworkID = 0xbeaded )
NetworkID are specific uint32s to identify separate networks
The default identifiers are MainNet (the main production network), TestNet (for network=TESTNET) and LocalNet (for network=LOCAL).
Custom NetworkIDs (network=CUSTOM) are generated from the "customnet" command line flag
func NewNetworkID ¶
NewNetworkID converts a string to a network id
type Parcel ¶
type Parcel struct { Address string // ? bytes - "" or nil for broadcast, otherwise the destination peer's hash. Payload []byte // contains filtered or unexported fields }
Parcel is the raw data interface between the network, the p2p package, and the application.
Type indicates the network or application type. Messages routed to and from the application will only have application types
Address is a unique internal identifier for origin or target of the parcel. For messages from the network to the application, the address will the id of the sender. Messages intended to be returned to the sender should bear the same address.
There are three special address constants:
Broadcast: The message will be sent to multiple peers as specified by the fanout FullBroadcast: The message will be sent to all peers RandomPeer: The message will be sent to one peer picked at random
The payload is arbitrary data defined at application level
func NewParcel ¶
NewParcel creates a new application message. The target should be either an identifier from a previous message, or one of the custom flags: Broadcast, BroadcastFull, RandomPeer
func (*Parcel) IsApplicationMessage ¶
IsApplicationMessage checks if the message is intended for the application
type ParcelChannel ¶
type ParcelChannel chan *Parcel
ParcelChannel is a channel that supports non-blocking sends
func (ParcelChannel) FillRatio ¶
func (pc ParcelChannel) FillRatio() float64
FillRatio returns a percentage [0.0,1.0] of how full the channel is
func (ParcelChannel) Reader ¶
func (pc ParcelChannel) Reader() <-chan *Parcel
Reader returns a read-only channel
type ParcelType ¶
type ParcelType uint16
ParcelType is a list of parcel types that this node understands
const ( // TypeHeartbeat is deprecated TypeHeartbeat ParcelType = iota // TypePing is sent if no other parcels have been sent in a while TypePing // TypePong is a response to a Ping TypePong // TypePeerRequest indicates a peer wants to be be updated of endpoints TypePeerRequest // TypePeerResponse carries a payload with protocol specific endpoints TypePeerResponse // TypeAlert is deprecated TypeAlert // TypeMessage carries an application message in the payload TypeMessage // TypeMessagePart is a partial message. deprecated in p2p 2.0 TypeMessagePart // TypeHandshake is the first parcel sent after making a connection TypeHandshake // TypeRejectAlternative is sent instead of a handshake if the server refuses connection TypeRejectAlternative )
func (ParcelType) String ¶
func (t ParcelType) String() string
type Peer ¶
type Peer struct { // current state, read only "constants" after the handshake IsIncoming bool Endpoint Endpoint Hash string // This is more of a connection ID than hash right now. // contains filtered or unexported fields }
Peer is an active connection to an endpoint in the network. Represents one lifetime of a connection and should not be restarted
func (*Peer) GetMetrics ¶
func (p *Peer) GetMetrics() PeerMetrics
GetMetrics returns live metrics for this connection
func (*Peer) LastSendAge ¶
func (*Peer) SendFillRatio ¶
SendFillRatio is a wrapper for the send channel's FillRatio
type PeerCache ¶
type PeerCache struct { Bans map[string]time.Time `json:"bans"` // can be ip or ip:port Peers []Endpoint `json:"peers"` }
PeerCache is the object that gets json-marshalled and written to disk
func (*PeerCache) WriteToFile ¶
type PeerHashCache ¶
type PeerHashCache struct {
// contains filtered or unexported fields
}
PeerHashCache keeps a list of the last X hashes for a specified interval. In this package, it is used to keep track of which messages were sent by a specific peer. Each peer has their own instance of PeerHashCache.
func NewPeerHashCache ¶
func NewPeerHashCache(buckets int, interval time.Duration) *PeerHashCache
NewPeerHashCache creates a new cache covering the time range of buckets * interval.
func (*PeerHashCache) Add ¶
func (pr *PeerHashCache) Add(hash [sha1.Size]byte)
Add a hash to the cache.
func (*PeerHashCache) Has ¶
func (pr *PeerHashCache) Has(hash [sha1.Size]byte) bool
Has returns true if the specified hash was seen.
func (*PeerHashCache) Stop ¶
func (pr *PeerHashCache) Stop()
Stop the PeerHashCache. Panics if called twice.
type PeerMetrics ¶
type PeerMetrics struct { Hash string PeerAddress string MomentConnected time.Time PeerQuality int32 LastReceive time.Time LastSend time.Time MessagesSent uint64 BytesSent uint64 MessagesReceived uint64 BytesReceived uint64 Incoming bool PeerType string ConnectionState string MPSDown float64 MPSUp float64 BPSDown float64 BPSUp float64 SendFillRatio float64 Dropped uint64 }
PeerMetrics is the data shared to the metrics hook
type PeerStore ¶
type PeerStore struct {
// contains filtered or unexported fields
}
PeerStore holds active Peers, managing them in a concurrency safe manner and providing lookup via various functions
func (*PeerStore) Add ¶
Add a peer to be managed. Returns an error if a peer with that hash is already tracked
func (*PeerStore) Connections ¶
Connections tests whether there is a peer connected from a specified ip address
func (*PeerStore) Remove ¶
Remove a specific peer if it exists. This checks by pointer reference and not by hash. If you have two distinct peer instances (A and B) with the same hash and add A, removing B has no effect, even if they have the same values
type Prometheus ¶
type Prometheus struct { Connections prometheus.Gauge Connecting prometheus.Gauge Incoming prometheus.Gauge Outgoing prometheus.Gauge ToNetwork prometheus.Gauge ToNetworkRatio prometheus.Gauge FromNetwork prometheus.Gauge FromNetworkRatio prometheus.Gauge CatRounds prometheus.Counter SendRoutines prometheus.Gauge ReceiveRoutines prometheus.Gauge ParcelsSent prometheus.Counter ParcelsReceived prometheus.Counter Invalid prometheus.Counter AppSent prometheus.Counter AppReceived prometheus.Counter ByteRateDown prometheus.Gauge ByteRateUp prometheus.Gauge MessageRateDown prometheus.Gauge MessageRateUp prometheus.Gauge DroppedPeerSend prometheus.Counter DroppedFromNetwork prometheus.Counter DroppedToNetwork prometheus.Counter ParcelSize prometheus.Histogram }
Prometheus holds all of the prometheus recording instruments
func (*Prometheus) Setup ¶
func (p *Prometheus) Setup()
Setup registers all of the instruments with prometheus once
type Protocol ¶
type Protocol interface { SendHandshake(*Handshake) error ReadHandshake() (*Handshake, error) Send(p *Parcel) error Receive() (*Parcel, error) Version() uint16 String() string }
Protocol is the interface for reading and writing parcels to the underlying connection. The job of a protocol is to encode a Parcel and send it over TCP to another instance of the same Protocol on the other end
Send: Parcel => Protocol Encoder => Protocol Format => TCP Receive: TCP => Protocol Format => Protocol Decoder => Parcel
Peer Sharing creates the protocol specific payload for a TypePeerShare Parcel
type ProtocolV10 ¶
type ProtocolV10 struct {
// contains filtered or unexported fields
}
ProtocolV10 is the protocol introduced by p2p 2.0. It is a slimmed down version of V9, reducing overhead
func (*ProtocolV10) MakePeerShare ¶
func (v10 *ProtocolV10) MakePeerShare(share []Endpoint) ([]byte, error)
MakePeerShare serializes a list of ips via json
func (*ProtocolV10) ParsePeerShare ¶
func (v10 *ProtocolV10) ParsePeerShare(payload []byte) ([]Endpoint, error)
ParsePeerShare parses a peer share payload
func (*ProtocolV10) ReadHandshake ¶
func (v10 *ProtocolV10) ReadHandshake() (*Handshake, error)
ReadHandshake for v10 is using the identical format to V9 for backward compatibility. It can't be easily told apart without first decoding the message, so the code is only implemented in v9, then upgraded to V10 based on the values
func (*ProtocolV10) Receive ¶
func (v10 *ProtocolV10) Receive() (*Parcel, error)
Receive converts a V10Msg back to a Parcel
func (*ProtocolV10) Send ¶
func (v10 *ProtocolV10) Send(p *Parcel) error
Send encodes a Parcel as V10Msg, calculates the crc and encodes it as gob
func (*ProtocolV10) SendHandshake ¶
func (v10 *ProtocolV10) SendHandshake(h *Handshake) error
type ProtocolV11 ¶
type ProtocolV11 struct {
// contains filtered or unexported fields
}
func (*ProtocolV11) MakePeerShare ¶
func (v11 *ProtocolV11) MakePeerShare(ps []Endpoint) ([]byte, error)
func (*ProtocolV11) ParsePeerShare ¶
func (v11 *ProtocolV11) ParsePeerShare(payload []byte) ([]Endpoint, error)
func (*ProtocolV11) ReadHandshake ¶
func (v11 *ProtocolV11) ReadHandshake() (*Handshake, error)
func (*ProtocolV11) Receive ¶
func (v11 *ProtocolV11) Receive() (*Parcel, error)
func (*ProtocolV11) Send ¶
func (v11 *ProtocolV11) Send(p *Parcel) error
func (*ProtocolV11) SendHandshake ¶
func (v11 *ProtocolV11) SendHandshake(hs *Handshake) error
func (*ProtocolV11) String ¶
func (v11 *ProtocolV11) String() string
func (*ProtocolV11) Version ¶
func (v11 *ProtocolV11) Version() uint16
type ProtocolV9 ¶
type ProtocolV9 struct {
// contains filtered or unexported fields
}
ProtocolV9 is the legacy format of the old p2p package which sends Parcels over the wire using gob. The V9Msg struct is equivalent to the old package's "Parcel" and "ParcelHeader" structure
func (*ProtocolV9) MakePeerShare ¶
func (v9 *ProtocolV9) MakePeerShare(ps []Endpoint) ([]byte, error)
MakePeerShare serializes the given endpoints to a V9Share encoded in json
func (*ProtocolV9) ParsePeerShare ¶
func (v9 *ProtocolV9) ParsePeerShare(payload []byte) ([]Endpoint, error)
ParsePeerShare unserializes the json V9Share
func (*ProtocolV9) ReadHandshake ¶
func (v9 *ProtocolV9) ReadHandshake() (*Handshake, error)
func (*ProtocolV9) Receive ¶
func (v9 *ProtocolV9) Receive() (*Parcel, error)
Receive a parcel from the network. Blocking.
func (*ProtocolV9) Send ¶
func (v9 *ProtocolV9) Send(p *Parcel) error
Send a parcel over the connection
func (*ProtocolV9) SendHandshake ¶
func (v9 *ProtocolV9) SendHandshake(h *Handshake) error
SendHandshake sends out a v9 structured handshake transform handshake into peer request
func (*ProtocolV9) String ¶
func (v9 *ProtocolV9) String() string
type ReadWriteCollector ¶
type ReadWriteCollector interface { io.Reader io.Writer StatsCollector }
type StatsCollector ¶
type V11Endpoint ¶
type V11Endpoint struct { Host string `protobuf:"bytes,1,opt,name=Host,proto3" json:"Host,omitempty"` Port string `protobuf:"bytes,2,opt,name=Port,proto3" json:"Port,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*V11Endpoint) Descriptor ¶
func (*V11Endpoint) Descriptor() ([]byte, []int)
func (*V11Endpoint) GetHost ¶
func (m *V11Endpoint) GetHost() string
func (*V11Endpoint) GetPort ¶
func (m *V11Endpoint) GetPort() string
func (*V11Endpoint) Marshal ¶
func (m *V11Endpoint) Marshal() (dAtA []byte, err error)
func (*V11Endpoint) MarshalToSizedBuffer ¶
func (m *V11Endpoint) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*V11Endpoint) ProtoMessage ¶
func (*V11Endpoint) ProtoMessage()
func (*V11Endpoint) Reset ¶
func (m *V11Endpoint) Reset()
func (*V11Endpoint) Size ¶
func (m *V11Endpoint) Size() (n int)
func (*V11Endpoint) String ¶
func (m *V11Endpoint) String() string
func (*V11Endpoint) Unmarshal ¶
func (m *V11Endpoint) Unmarshal(dAtA []byte) error
func (*V11Endpoint) XXX_DiscardUnknown ¶
func (m *V11Endpoint) XXX_DiscardUnknown()
func (*V11Endpoint) XXX_Marshal ¶
func (m *V11Endpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*V11Endpoint) XXX_Merge ¶
func (m *V11Endpoint) XXX_Merge(src proto.Message)
func (*V11Endpoint) XXX_Size ¶
func (m *V11Endpoint) XXX_Size() int
func (*V11Endpoint) XXX_Unmarshal ¶
func (m *V11Endpoint) XXX_Unmarshal(b []byte) error
type V11Handshake ¶
type V11Handshake struct { Type uint32 `protobuf:"varint,1,opt,name=Type,proto3" json:"Type,omitempty"` Network uint32 `protobuf:"varint,2,opt,name=Network,proto3" json:"Network,omitempty"` Version uint32 `protobuf:"varint,3,opt,name=Version,proto3" json:"Version,omitempty"` NodeID uint32 `protobuf:"varint,4,opt,name=NodeID,proto3" json:"NodeID,omitempty"` ListenPort string `protobuf:"bytes,5,opt,name=ListenPort,proto3" json:"ListenPort,omitempty"` Loopback uint64 `protobuf:"varint,6,opt,name=Loopback,proto3" json:"Loopback,omitempty"` Alternatives []*V11Endpoint `protobuf:"bytes,7,rep,name=Alternatives,proto3" json:"Alternatives,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*V11Handshake) Descriptor ¶
func (*V11Handshake) Descriptor() ([]byte, []int)
func (*V11Handshake) GetAlternatives ¶
func (m *V11Handshake) GetAlternatives() []*V11Endpoint
func (*V11Handshake) GetListenPort ¶
func (m *V11Handshake) GetListenPort() string
func (*V11Handshake) GetLoopback ¶
func (m *V11Handshake) GetLoopback() uint64
func (*V11Handshake) GetNetwork ¶
func (m *V11Handshake) GetNetwork() uint32
func (*V11Handshake) GetNodeID ¶
func (m *V11Handshake) GetNodeID() uint32
func (*V11Handshake) GetType ¶
func (m *V11Handshake) GetType() uint32
func (*V11Handshake) GetVersion ¶
func (m *V11Handshake) GetVersion() uint32
func (*V11Handshake) Marshal ¶
func (m *V11Handshake) Marshal() (dAtA []byte, err error)
func (*V11Handshake) MarshalToSizedBuffer ¶
func (m *V11Handshake) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*V11Handshake) ProtoMessage ¶
func (*V11Handshake) ProtoMessage()
func (*V11Handshake) Reset ¶
func (m *V11Handshake) Reset()
func (*V11Handshake) Size ¶
func (m *V11Handshake) Size() (n int)
func (*V11Handshake) String ¶
func (m *V11Handshake) String() string
func (*V11Handshake) Unmarshal ¶
func (m *V11Handshake) Unmarshal(dAtA []byte) error
func (*V11Handshake) XXX_DiscardUnknown ¶
func (m *V11Handshake) XXX_DiscardUnknown()
func (*V11Handshake) XXX_Marshal ¶
func (m *V11Handshake) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*V11Handshake) XXX_Merge ¶
func (m *V11Handshake) XXX_Merge(src proto.Message)
func (*V11Handshake) XXX_Size ¶
func (m *V11Handshake) XXX_Size() int
func (*V11Handshake) XXX_Unmarshal ¶
func (m *V11Handshake) XXX_Unmarshal(b []byte) error
type V11Msg ¶
type V11Msg struct { Type uint32 `protobuf:"varint,1,opt,name=Type,proto3" json:"Type,omitempty"` Payload []byte `protobuf:"bytes,2,opt,name=Payload,proto3" json:"Payload,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*V11Msg) Descriptor ¶
func (*V11Msg) GetPayload ¶
func (*V11Msg) MarshalToSizedBuffer ¶
func (*V11Msg) ProtoMessage ¶
func (*V11Msg) ProtoMessage()
func (*V11Msg) XXX_DiscardUnknown ¶
func (m *V11Msg) XXX_DiscardUnknown()
func (*V11Msg) XXX_Marshal ¶
func (*V11Msg) XXX_Unmarshal ¶
type V11Share ¶
type V11Share struct {}
func (*V11Share) Descriptor ¶
func (*V11Share) GetShare ¶
func (m *V11Share) GetShare() []*V11Endpoint
func (*V11Share) MarshalToSizedBuffer ¶
func (*V11Share) ProtoMessage ¶
func (*V11Share) ProtoMessage()
func (*V11Share) XXX_DiscardUnknown ¶
func (m *V11Share) XXX_DiscardUnknown()
func (*V11Share) XXX_Marshal ¶
func (*V11Share) XXX_Unmarshal ¶
type V9Header ¶
type V9Header struct { Network NetworkID Version uint16 Type ParcelType Length uint32 TargetPeer string Crc32 uint32 PartNo uint16 PartsTotal uint16 NodeID uint64 PeerAddress string PeerPort string AppHash string AppType string }
V9Header carries meta information about the parcel
Source Files ¶
- configuration.go
- controller.go
- controller_cat.go
- controller_connections.go
- controller_persistence.go
- controller_routing.go
- controller_run.go
- dialer.go
- endpoint.go
- handshake.go
- info.go
- limiter.go
- lockSource.go
- metricsReadWriter.go
- network.go
- networkId.go
- parcel.go
- parcelChannel.go
- parcelType.go
- peer.go
- peerHashCache.go
- peerStore.go
- peerUtil.go
- prometheus.go
- protocol.go
- protocolV10.go
- protocolV11.go
- protocolV11.pb.go
- protocolV9.go
- seed.go
- util.go