Documentation ¶
Index ¶
- Variables
- func Connect2Switches(switches []*Switch, i, j int)
- func ExternalIPv4() (string, error)
- type BaseReactor
- type DefaultListener
- func (l *DefaultListener) Connections() <-chan net.Conn
- func (l *DefaultListener) ExternalAddress() *NetAddress
- func (l *DefaultListener) InternalAddress() *NetAddress
- func (l *DefaultListener) NetListener() net.Listener
- func (l *DefaultListener) OnStart() error
- func (l *DefaultListener) OnStop()
- func (l *DefaultListener) String() string
- type IPeerSet
- type Listener
- type NetAddress
- func CreateRoutableAddr() (addr string, netAddr *NetAddress)
- func NewLANNetAddressIPPort(ip net.IP, port uint16) *NetAddress
- func NewNetAddress(addr net.Addr) *NetAddress
- func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress
- func NewNetAddressString(addr string) (*NetAddress, error)
- func NewNetAddressStrings(addrs []string) ([]*NetAddress, error)
- func (na *NetAddress) Dial() (net.Conn, error)
- func (na *NetAddress) DialString() string
- func (na *NetAddress) DialTimeout(timeout time.Duration) (net.Conn, error)
- func (na *NetAddress) DialTimeoutWithProxy(proxy *socks.Proxy, timeout time.Duration) (net.Conn, error)
- func (na *NetAddress) Equals(other interface{}) bool
- func (na *NetAddress) Local() bool
- func (na *NetAddress) RFC1918() bool
- func (na *NetAddress) RFC3849() bool
- func (na *NetAddress) RFC3927() bool
- func (na *NetAddress) RFC3964() bool
- func (na *NetAddress) RFC4193() bool
- func (na *NetAddress) RFC4380() bool
- func (na *NetAddress) RFC4843() bool
- func (na *NetAddress) RFC4862() bool
- func (na *NetAddress) RFC6052() bool
- func (na *NetAddress) RFC6145() bool
- func (na *NetAddress) ReachabilityTo(o *NetAddress) int
- func (na *NetAddress) Routable() bool
- func (na *NetAddress) String() string
- func (na *NetAddress) Valid() bool
- type NodeInfo
- type Peer
- func (p *Peer) Addr() net.Addr
- func (p *Peer) CanSend(chID byte) bool
- func (pc Peer) CloseConn()
- func (p *Peer) Equals(other *Peer) bool
- func (pc Peer) HandshakeTimeout(ourNodeInfo *NodeInfo, timeout time.Duration) (*NodeInfo, error)
- func (p *Peer) ID() string
- func (p *Peer) IsLAN() bool
- func (p *Peer) IsOutbound() bool
- func (p *Peer) OnStart() error
- func (p *Peer) OnStop()
- func (p *Peer) PubKey() crypto.PubKeyEd25519
- func (p *Peer) Send(chID byte, msg interface{}) bool
- func (p *Peer) ServiceFlag() consensus.ServiceFlag
- func (p *Peer) String() string
- func (p *Peer) TrafficStatus() (*flowrate.Status, *flowrate.Status)
- func (p *Peer) TrySend(chID byte, msg interface{}) bool
- type PeerConfig
- type PeerSet
- type Reactor
- type Security
- type Switch
- func (sw *Switch) AddListener(l Listener)
- func (sw *Switch) AddPeer(pc *peerConn, isLAN bool) error
- func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor
- func (sw *Switch) DialPeerWithAddress(addr *NetAddress) error
- func (sw *Switch) IsBanned(ip string, level byte, reason string) bool
- func (sw *Switch) IsDialing(addr *NetAddress) bool
- func (sw *Switch) IsListening() bool
- func (sw *Switch) Listeners() []Listener
- func (sw *Switch) NodeInfo() *NodeInfo
- func (sw *Switch) NumPeers() (lan, outbound, inbound, dialing int)
- func (sw *Switch) OnStart() error
- func (sw *Switch) OnStop()
- func (sw *Switch) Peers() *PeerSet
- func (sw *Switch) StopPeerForError(peer *Peer, reason interface{})
- func (sw *Switch) StopPeerGracefully(peerID string)
Constants ¶
This section is empty.
Variables ¶
var ( ErrDuplicatePeer = errors.New("Duplicate peer") ErrConnectSelf = errors.New("Connect self") ErrConnectSpvPeer = errors.New("Outbound connect spv peer") )
pre-define errors for connecting fail
var PanicOnAddPeerErr = false
PanicOnAddPeerErr add peer error
Functions ¶
func Connect2Switches ¶
Connect2Switches will connect switches i and j via net.Pipe() Blocks until a conection is established. NOTE: caller ensures i and j are within bounds
func ExternalIPv4 ¶
ExternalIPv4 returns the first IPv4 available.
Types ¶
type BaseReactor ¶
type BaseReactor struct { cmn.BaseService // Provides Start, Stop, .Quit Switch *Switch }
BaseReactor base service of a reactor
func NewBaseReactor ¶
func NewBaseReactor(name string, impl Reactor) *BaseReactor
NewBaseReactor create new base Reactor
func (*BaseReactor) AddPeer ¶
func (*BaseReactor) AddPeer(peer *Peer)
AddPeer is called by the switch when a new peer is added
func (*BaseReactor) GetChannels ¶
func (*BaseReactor) GetChannels() []*connection.ChannelDescriptor
GetChannels returns the list of channel descriptors
func (*BaseReactor) Receive ¶
func (*BaseReactor) Receive(chID byte, peer *Peer, msgBytes []byte)
Receive is called when msgBytes is received from peer
func (*BaseReactor) RemovePeer ¶
func (*BaseReactor) RemovePeer(peer *Peer, reason interface{})
RemovePeer is called by the switch when the peer is stopped (due to error or other reason)
func (*BaseReactor) SetSwitch ¶
func (br *BaseReactor) SetSwitch(sw *Switch)
SetSwitch setting a switch for reactor
type DefaultListener ¶
type DefaultListener struct { cmn.BaseService // contains filtered or unexported fields }
DefaultListener Implements VOCCHAINd server Listener
func (*DefaultListener) Connections ¶
func (l *DefaultListener) Connections() <-chan net.Conn
Connections a channel of inbound connections. It gets closed when the listener closes.
func (*DefaultListener) ExternalAddress ¶
func (l *DefaultListener) ExternalAddress() *NetAddress
ExternalAddress listener external address for remote peer dial
func (*DefaultListener) InternalAddress ¶
func (l *DefaultListener) InternalAddress() *NetAddress
InternalAddress listener internal address
func (*DefaultListener) NetListener ¶
func (l *DefaultListener) NetListener() net.Listener
NetListener the returned listener is already Accept()'ing. So it's not suitable to pass into http.Serve().
func (*DefaultListener) String ¶
func (l *DefaultListener) String() string
String string of default listener
type Listener ¶
type Listener interface { Connections() <-chan net.Conn InternalAddress() *NetAddress ExternalAddress() *NetAddress String() string Stop() bool }
Listener subset of the methods of DefaultListener
func GetListener ¶
GetListener get listener and listen address.
type NetAddress ¶
NetAddress defines information about a peer on the network including its IP address, and port.
func CreateRoutableAddr ¶
func CreateRoutableAddr() (addr string, netAddr *NetAddress)
func NewLANNetAddressIPPort ¶
func NewLANNetAddressIPPort(ip net.IP, port uint16) *NetAddress
NewLANNetAddressIPPort returns a new LAN NetAddress using the provided IP and port number.
func NewNetAddress ¶
func NewNetAddress(addr net.Addr) *NetAddress
NewNetAddress returns a new NetAddress using the provided TCP address. When testing, other net.Addr (except TCP) will result in using 0.0.0.0:0. When normal run, other net.Addr (except TCP) will panic. TODO: socks proxies?
func NewNetAddressIPPort ¶
func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress
NewNetAddressIPPort returns a new NetAddress using the provided IP and port number.
func NewNetAddressString ¶
func NewNetAddressString(addr string) (*NetAddress, error)
NewNetAddressString returns a new NetAddress using the provided address in the form of "IP:Port". Also resolves the host if host is not an IP.
func NewNetAddressStrings ¶
func NewNetAddressStrings(addrs []string) ([]*NetAddress, error)
NewNetAddressStrings returns an array of NetAddress'es build using the provided strings.
func (*NetAddress) Dial ¶
func (na *NetAddress) Dial() (net.Conn, error)
Dial calls net.Dial on the address.
func (*NetAddress) DialString ¶
func (na *NetAddress) DialString() string
DialString dial address string representation
func (*NetAddress) DialTimeout ¶
DialTimeout calls net.DialTimeout on the address.
func (*NetAddress) DialTimeoutWithProxy ¶
func (na *NetAddress) DialTimeoutWithProxy(proxy *socks.Proxy, timeout time.Duration) (net.Conn, error)
DialTimeoutWithProxy calls socks.Proxy.DialTimeout on the address.
func (*NetAddress) Equals ¶
func (na *NetAddress) Equals(other interface{}) bool
Equals reports whether na and other are the same addresses.
func (*NetAddress) Local ¶
func (na *NetAddress) Local() bool
Local returns true if it is a local address.
func (*NetAddress) RFC1918 ¶
func (na *NetAddress) RFC1918() bool
RFC1918 IPv4 Private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)
func (*NetAddress) RFC3849 ¶
func (na *NetAddress) RFC3849() bool
RFC3849 IPv6 Documentation address (2001:0DB8::/32)
func (*NetAddress) RFC3927 ¶
func (na *NetAddress) RFC3927() bool
RFC3927 IPv4 Autoconfig (169.254.0.0/16)
func (*NetAddress) RFC4193 ¶
func (na *NetAddress) RFC4193() bool
RFC4193 IPv6 unique local (FC00::/7)
func (*NetAddress) RFC4380 ¶
func (na *NetAddress) RFC4380() bool
RFC4380 IPv6 Teredo tunneling (2001::/32)
func (*NetAddress) RFC4843 ¶
func (na *NetAddress) RFC4843() bool
RFC4843 IPv6 ORCHID: (2001:10::/28)
func (*NetAddress) RFC4862 ¶
func (na *NetAddress) RFC4862() bool
RFC4862 IPv6 Autoconfig (FE80::/64)
func (*NetAddress) RFC6052 ¶
func (na *NetAddress) RFC6052() bool
RFC6052 IPv6 well known prefix (64:FF9B::/96)
func (*NetAddress) RFC6145 ¶
func (na *NetAddress) RFC6145() bool
RFC6145 IPv6 IPv4 translated address ::FFFF:0:0:0/96
func (*NetAddress) ReachabilityTo ¶
func (na *NetAddress) ReachabilityTo(o *NetAddress) int
ReachabilityTo checks whenever o can be reached from na.
func (*NetAddress) Routable ¶
func (na *NetAddress) Routable() bool
Routable returns true if the address is routable.
func (*NetAddress) Valid ¶
func (na *NetAddress) Valid() bool
Valid For IPv4 these are either a 0 or all bits set address. For IPv6 a zero address or one that matches the RFC3849 documentation address format.
type NodeInfo ¶
type NodeInfo struct { PubKey crypto.PubKeyEd25519 `json:"pub_key"` Moniker string `json:"moniker"` Network string `json:"network"` RemoteAddr string `json:"remote_addr"` ListenAddr string `json:"listen_addr"` Version string `json:"version"` // major.minor.revision // other application specific data //field 0: node service flags. field 1: node alias. Other []string `json:"other"` }
NodeInfo peer node info
func NewNodeInfo ¶
func (*NodeInfo) CompatibleWith ¶
CompatibleWith checks if two NodeInfo are compatible with eachother. CONTRACT: two nodes are compatible if the major version matches and network match
func (*NodeInfo) GetNetwork ¶
GetNetwork get node info network field
func (*NodeInfo) RemoteAddrHost ¶
RemoteAddrHost peer external ip address
type Peer ¶
type Peer struct { cmn.BaseService *NodeInfo Key string // contains filtered or unexported fields }
Peer represent a VOCCHAIN network node
func CreateRandomPeer ¶
func (Peer) CloseConn ¶
func (pc Peer) CloseConn()
CloseConn should be used when the peer was created, but never started.
func (Peer) HandshakeTimeout ¶
HandshakeTimeout performs a handshake between a given node and the peer. NOTE: blocking
func (*Peer) IsOutbound ¶
IsOutbound returns true if the connection is outbound, false otherwise.
func (*Peer) PubKey ¶
func (p *Peer) PubKey() crypto.PubKeyEd25519
PubKey returns peer's public key.
func (*Peer) Send ¶
Send msg to the channel identified by chID byte. Returns false if the send queue is full after timeout, specified by MConnection.
func (*Peer) ServiceFlag ¶
func (p *Peer) ServiceFlag() consensus.ServiceFlag
ServiceFlag return the ServiceFlag of this peer
func (*Peer) TrafficStatus ¶
TrafficStatus return the in and out traffic status
type PeerConfig ¶
type PeerConfig struct { HandshakeTimeout time.Duration `mapstructure:"handshake_timeout"` // times are in seconds DialTimeout time.Duration `mapstructure:"dial_timeout"` ProxyAddress string `mapstructure:"proxy_address"` ProxyUsername string `mapstructure:"proxy_username"` ProxyPassword string `mapstructure:"proxy_password"` MConfig *connection.MConnConfig `mapstructure:"connection"` }
PeerConfig is a Peer configuration.
func DefaultPeerConfig ¶
func DefaultPeerConfig(config *cfg.P2PConfig) *PeerConfig
DefaultPeerConfig returns the default config.
type PeerSet ¶
type PeerSet struct {
// contains filtered or unexported fields
}
PeerSet is a special structure for keeping a table of peers. Iteration over the peers is super fast and thread-safe.
func NewPeerSet ¶
func NewPeerSet() *PeerSet
NewPeerSet creates a new peerSet with a list of initial capacity of 256 items.
func (*PeerSet) Add ¶
Add adds the peer to the PeerSet. Returns false if peer with key (PubKeyEd25519) is already set
func (*PeerSet) Has ¶
Has returns true if the PeerSet contains the peer referred to by this peerKey.
type Reactor ¶
type Reactor interface { cmn.Service // Start, Stop // SetSwitch allows setting a switch. SetSwitch(*Switch) // GetChannels returns the list of channel descriptors. GetChannels() []*connection.ChannelDescriptor // AddPeer is called by the switch when a new peer is added. AddPeer(peer *Peer) error // RemovePeer is called by the switch when the peer is stopped (due to error // or other reason). RemovePeer(peer *Peer, reason interface{}) // Receive is called when msgBytes is received from peer. // // NOTE reactor can not keep msgBytes around after Receive completes without // copying. // // CONTRACT: msgBytes are not nil. Receive(chID byte, peer *Peer, msgBytes []byte) }
Reactor is responsible for handling incoming messages of one or more `Channels`
type Switch ¶
type Switch struct { cmn.BaseService Config *cfg.Config // contains filtered or unexported fields }
Switch handles peer connections and exposes an API to receive incoming messages on `Reactors`. Each `Reactor` is responsible for handling incoming messages of one or more `Channels`. So while sending outgoing messages is typically performed on the peer, incoming messages are received on the reactor.
func MakeSwitch ¶
func (*Switch) AddListener ¶
AddListener adds the given listener to the switch for listening to incoming peer connections. NOTE: Not goroutine safe.
func (*Switch) AddPeer ¶
AddPeer performs the P2P handshake with a peer that already has a SecretConnection. If all goes well, it starts the peer and adds it to the switch. NOTE: This performs a blocking handshake before the peer is added. CONTRACT: If error is returned, peer is nil, and conn is immediately closed.
func (*Switch) AddReactor ¶
AddReactor adds the given reactor to the switch. NOTE: Not goroutine safe.
func (*Switch) DialPeerWithAddress ¶
func (sw *Switch) DialPeerWithAddress(addr *NetAddress) error
DialPeerWithAddress dial node from net address
func (*Switch) IsDialing ¶
func (sw *Switch) IsDialing(addr *NetAddress) bool
IsDialing prevent duplicate dialing
func (*Switch) IsListening ¶
IsListening returns true if the switch has at least one listener. NOTE: Not goroutine safe.
func (*Switch) Listeners ¶
Listeners returns the list of listeners the switch listens on. NOTE: Not goroutine safe.
func (*Switch) NumPeers ¶
NumPeers Returns the count of outbound/inbound and outbound-dialing peers.
func (*Switch) OnStart ¶
OnStart implements BaseService. It starts all the reactors, peers, and listeners.
func (*Switch) OnStop ¶
func (sw *Switch) OnStop()
OnStop implements BaseService. It stops all listeners, peers, and reactors.
func (*Switch) StopPeerForError ¶
StopPeerForError disconnects from a peer due to external error.
func (*Switch) StopPeerGracefully ¶
StopPeerGracefully disconnect from a peer gracefully.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
discover
|
|
dht
Package discv5 implements the RLPx v5 Topic Discovery Protocol.
|
Package discv5 implements the RLPx v5 Topic Discovery Protocol. |
Package netutil contains extensions to the net package.
|
Package netutil contains extensions to the net package. |
Taken from taipei-torrent Just enough UPnP to be able to forward ports
|
Taken from taipei-torrent Just enough UPnP to be able to forward ports |