Documentation ¶
Overview ¶
Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- func GetFreePort() (port int, err error)
- func GetFreePortList(count int) (ports []int, err error)
- func ParseListeners(addrs []string) ([]net.Addr, error)
- func SetPortForListeners(listeners []string, port int) []string
- type ChainPort
- type ChainsPortIndex
- type Config
- type ConnManager
- func (cm *ConnManager) AddRebroadcastInventory(iv *wire.InvVect, data interface{})
- func (cm *ConnManager) BroadcastMessage(msg wire.Message)
- func (cm *ConnManager) Connect(addr string, permanent bool) error
- func (cm *ConnManager) ConnectedCount() int32
- func (cm *ConnManager) ConnectedPeers() []netsync.ServerPeer
- func (cm *ConnManager) DisconnectByAddr(addr string) error
- func (cm *ConnManager) DisconnectByID(id int32) error
- func (cm *ConnManager) NetTotals() (uint64, uint64)
- func (cm *ConnManager) PersistentPeers() []netsync.ServerPeer
- func (cm *ConnManager) RelayTransactions(txns []*mempool.TxDesc)
- func (cm *ConnManager) RemoveByAddr(addr string) error
- func (cm *ConnManager) RemoveByID(id int32) error
- type ConnectNodeMsg
- type DisconnectNodeMsg
- type GetAddedNodesMsg
- type GetConnCountMsg
- type GetOutboundGroup
- type GetPeerStatsMsg
- type GetPeersMsg
- type INodeServer
- type ListenOpts
- type NAT
- type PeerStateStats
- type PeersConfig
- type RelayMsg
- type RemoveNodeMsg
- type Server
- func (server *Server) AddBytesReceived(bytesReceived uint64)
- func (server *Server) AddBytesSent(bytesSent uint64)
- func (server *Server) AddRebroadcastInventory(iv *wire.InvVect, data interface{})
- func (server *Server) AnnounceNewTransactions(txns []*mempool.TxDesc)
- func (server *Server) BroadcastMessage(msg wire.Message, exclPeers ...*serverPeer)
- func (server *Server) ConnectedCount() int32
- func (server *Server) NetTotals() (uint64, uint64)
- func (server *Server) OutboundGroupCount(key string) int
- func (server *Server) P2PConnManager() netsync.P2PConnManager
- func (server *Server) PeerStateStats() PeerStateStats
- func (server *Server) Query(value interface{})
- func (server *Server) RelayInventory(invVect *wire.InvVect, data interface{})
- func (server *Server) RelayTransactions(txns []*mempool.TxDesc)
- func (server *Server) RemoveRebroadcastInventory(iv *wire.InvVect)
- func (server *Server) Run(ctx context.Context)
- func (server *Server) ScheduleShutdown(duration time.Duration)
- func (server *Server) Stop() error
- func (server *Server) TransactionConfirmed(tx *jaxutil.Tx)
- func (server *Server) UpdatePeerHeights(latestBlkHash *chainhash.Hash, latestHeight int32, updateSource *peer.Peer)
- func (server *Server) WaitForShutdown()
- type UpdatePeerHeightsMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFreePort ¶
func GetFreePortList ¶
func ParseListeners ¶
ParseListeners determines whether each listen address is IPv4 and IPv6 and returns a slice of appropriate net.Addrs to listen on with TCP. It also properly detects addresses which apply to "all interfaces" and adds the address as both IPv4 and IPv6.
func SetPortForListeners ¶
Types ¶
type ChainsPortIndex ¶
type ChainsPortIndex struct {
// contains filtered or unexported fields
}
func NewPortsIndex ¶
func NewPortsIndex() *ChainsPortIndex
func (*ChainsPortIndex) Add ¶
func (ind *ChainsPortIndex) Add(shardID uint32, port int)
func (*ChainsPortIndex) Delete ¶
func (ind *ChainsPortIndex) Delete(shardID uint32)
type Config ¶
type Config struct { Peers []string `toml:"peers" ` Listeners []string `toml:"listeners"` AgentBlacklist []string `toml:"agent_blacklist"` AgentWhitelist []string `toml:"agent_whitelist"` DisableListen bool `toml:"disable_listen"` // Disable listening for incoming connections -- NOTE: Listening is automatically disabled if the --connect or --proxy options are used without also specifying listen interfaces via --listen ExternalIPs []string `toml:"external_ips"` // Add an ip to the list of local addresses we claim to listen on to peers ConnectPeers []string `toml:"connect_peers"` // Connect only to the specified peers at startup BanDuration time.Duration `toml:"ban_duration"` // How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second BanThreshold uint32 `toml:"ban_threshold"` // Maximum allowed ban score before disconnecting and banning misbehaving peers. DisableBanning bool `toml:"disable_banning"` // Disable banning of misbehaving peers BlocksOnly bool `toml:"blocks_only"` // Do not accept transactions from remote peers. DisableOutbound bool `toml:"disable_outbound"` OnionProxy string `toml:"onion_proxy"` // Connect to tor hidden services via SOCKS5 proxy (eg. 127.0.0.1:9050) OnionProxyPass string `toml:"onion_proxy_pass"` // Password for onion proxy Server OnionProxyUser string `toml:"onion_proxy_user"` // Username for onion proxy Server Proxy string `toml:"proxy"` // Connect via SOCKS5 proxy (eg. 127.0.0.1:9050) ProxyPass string `toml:"proxy_pass"` // Password for proxy Server ProxyUser string `toml:"proxy_user"` // Username for proxy Server RejectNonStd bool `toml:"reject_non_std"` // Reject non-standard transactions regardless of the default settings for the active network. TrickleInterval time.Duration `toml:"trickle_interval"` // Minimum time between attempts to send new inventory to a connected Server DisableDNSSeed bool `toml:"disable_dns_seed"` // Disable DNS seeding for peers NoOnion bool `toml:"no_onion"` // Disable connecting to tor hidden services NoPeerBloomFilters bool `toml:"no_peer_bloom_filters"` // Disable bloom filtering support Upnp bool `toml:"upnp"` // Use UPnP to map our listening port outside of NAT ShardDefaultPort int `toml:"shard_default_port"` // Port on which to start looking for shards on peer servers PublicIPAddress string `toml:"public_ip_address"` Oniondial func(string, string, time.Duration) (net.Conn, error) `toml:"-" yaml:"-"` Dial func(string, string, time.Duration) (net.Conn, error) `toml:"-" yaml:"-"` Lookup func(string) ([]net.IP, error) `toml:"-" yaml:"-"` GetChainPort func(shardID uint32) (int, bool) `toml:"-" yaml:"-"` }
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
ConnManager provides a connection manager for use with the RPC Server and implements the P2PConnManager interface.
func (*ConnManager) AddRebroadcastInventory ¶
func (cm *ConnManager) AddRebroadcastInventory(iv *wire.InvVect, data interface{})
AddRebroadcastInventory adds the provided inventory to the list of inventories to be rebroadcast at random intervals until they show up in a block.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) BroadcastMessage ¶
func (cm *ConnManager) BroadcastMessage(msg wire.Message)
BroadcastMessage sends the provided message to all currently connected peers.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) Connect ¶
func (cm *ConnManager) Connect(addr string, permanent bool) error
Connect adds the provided address as a new outbound peer. The permanent flag indicates whether or not to make the peer persistent and reconnect if the connection is lost. Attempting to connect to an already existing peer will return an error.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) ConnectedCount ¶
func (cm *ConnManager) ConnectedCount() int32
ConnectedCount returns the number of currently connected peers.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) ConnectedPeers ¶
func (cm *ConnManager) ConnectedPeers() []netsync.ServerPeer
ConnectedPeers returns an array consisting of all connected peers.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) DisconnectByAddr ¶
func (cm *ConnManager) DisconnectByAddr(addr string) error
DisconnectByAddr disconnects the peer associated with the provided address. This applies to both inbound and outbound peers. Attempting to remove an address that does not exist will return an error.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) DisconnectByID ¶
func (cm *ConnManager) DisconnectByID(id int32) error
DisconnectByID disconnects the peer associated with the provided id. This applies to both inbound and outbound peers. Attempting to remove an id that does not exist will return an error.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) NetTotals ¶
func (cm *ConnManager) NetTotals() (uint64, uint64)
NetTotals returns the sum of all bytes received and sent across the network for all peers.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) PersistentPeers ¶
func (cm *ConnManager) PersistentPeers() []netsync.ServerPeer
PersistentPeers returns an array consisting of all the added persistent peers.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) RelayTransactions ¶
func (cm *ConnManager) RelayTransactions(txns []*mempool.TxDesc)
RelayTransactions generates and relays inventory vectors for all of the passed transactions to all connected peers.
func (*ConnManager) RemoveByAddr ¶
func (cm *ConnManager) RemoveByAddr(addr string) error
RemoveByAddr removes the peer associated with the provided address from the list of persistent peers. Attempting to remove an address that does not exist will return an error.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
func (*ConnManager) RemoveByID ¶
func (cm *ConnManager) RemoveByID(id int32) error
RemoveByID removes the peer associated with the provided id from the list of persistent peers. Attempting to remove an id that does not exist will return an error.
This function is safe for concurrent access and is part of the P2PConnManager interface implementation.
type ConnectNodeMsg ¶
type DisconnectNodeMsg ¶
type GetAddedNodesMsg ¶
type GetAddedNodesMsg struct {
Reply chan []*serverPeer
}
type GetConnCountMsg ¶
type GetConnCountMsg struct {
Reply chan int32
}
type GetOutboundGroup ¶
type GetPeerStatsMsg ¶
type GetPeerStatsMsg struct {
Reply chan PeerStateStats
}
type GetPeersMsg ¶
type GetPeersMsg struct {
Reply chan []*serverPeer
}
type INodeServer ¶
type ListenOpts ¶
type NAT ¶
type NAT interface { // GetExternalAddress gets the external address from outside the NAT. GetExternalAddress() (addr net.IP, err error) // AddPortMapping adds a port mapping for protocol ("udp" or "tcp") from external port to // internal port with description lasting for timeout. AddPortMapping(protocol string, externalPort, internalPort int, description string, timeout int) (mappedExternalPort int, err error) // DeletePortMapping removes a previously added port mapping from external port to // internal port. DeletePortMapping(protocol string, externalPort, internalPort int) (err error) }
NAT is an interface representing a NAT traversal options for example UPNP or NAT-PMP. It provides methods to query and manipulate this traversal to allow access to services.
type PeerStateStats ¶
type PeersConfig ¶
type PeersConfig struct { DisableBanning bool // Disable banning of misbehaving peers BanThreshold uint32 // Maximum allowed ban score before disconnecting and banning misbehaving peers. BlocksOnly bool // Do not accept transactions from remote peers. Proxy string // Connect via SOCKS5 proxy (eg. 127.0.0.1:9050) TrickleInterval time.Duration // Minimum time between attempts to send new inventory to a connected Server }
type RelayMsg ¶
RelayMsg packages an inventory vector along with the newly discovered inventory so the relay has access to that information.
type RemoveNodeMsg ¶
type Server ¶
type Server struct { ConnManager *connmgr.ConnManager // contains filtered or unexported fields }
Server provides a bitcoin server for handling communications to and from bitcoin peers.
func NewServer ¶
func NewServer(cfg *Config, chainProvider *cprovider.ChainProvider, amgr *addrmgr.AddrManager, opts ListenOpts) (*Server, error)
NewServer returns a new jaxnetd p2p server configured to listen on addr for the bitcoin network type specified by ChainParams. Use start to begin accepting connections from peers.
func (*Server) AddBytesReceived ¶
AddBytesReceived adds the passed number of bytes to the total bytes received counter for the server. It is safe for concurrent access.
func (*Server) AddBytesSent ¶
AddBytesSent adds the passed number of bytes to the total bytes sent counter for the server. It is safe for concurrent access.
func (*Server) AddRebroadcastInventory ¶
AddRebroadcastInventory adds 'iv' to the list of inventories to be rebroadcasted at random intervals until they show up in a block.
func (*Server) AnnounceNewTransactions ¶
AnnounceNewTransactions generates and relays inventory vectors and notifies both websocket and getblocktemplate long poll clients of the passed transactions. This function should be called whenever new transactions are added to the mempool.
func (*Server) BroadcastMessage ¶
BroadcastMessage sends msg to all peers currently connected to the Server except those in the passed peers to exclude.
func (*Server) ConnectedCount ¶
ConnectedCount returns the number of currently connected peers.
func (*Server) NetTotals ¶
NetTotals returns the sum of all bytes received and sent across the network for all peers. It is safe for concurrent access.
func (*Server) OutboundGroupCount ¶
OutboundGroupCount returns the number of peers connected to the given outbound group key.
func (*Server) P2PConnManager ¶
func (server *Server) P2PConnManager() netsync.P2PConnManager
func (*Server) PeerStateStats ¶
func (server *Server) PeerStateStats() PeerStateStats
ConnectedCount returns the number of currently connected peers.
func (*Server) RelayInventory ¶
RelayInventory relays the passed inventory vector to all connected peers that are not already known to have it.
func (*Server) RelayTransactions ¶
RelayTransactions generates and relays inventory vectors for all of the passed transactions to all connected peers.
func (*Server) RemoveRebroadcastInventory ¶
RemoveRebroadcastInventory removes 'iv' from the list of items to be rebroadcasted if present.
func (*Server) ScheduleShutdown ¶
ScheduleShutdown schedules a Server shutdown after the specified duration. It also dynamically adjusts how often to warn the Server is going down based on remaining duration.
func (*Server) Stop ¶
Stop gracefully shuts down the Server by stopping and disconnecting all peers and the main listener.
func (*Server) TransactionConfirmed ¶
TransactionConfirmed has one confirmation on the main BlockChain. Now we can mark it as no longer needing rebroadcasting.
func (*Server) UpdatePeerHeights ¶
func (server *Server) UpdatePeerHeights(latestBlkHash *chainhash.Hash, latestHeight int32, updateSource *peer.Peer)
UpdatePeerHeights updates the heights of all peers who have have announced the latest connected main BlockChain block, or a recognized orphan. These height updates allow us to dynamically refresh peer heights, ensuring sync peer selection has access to the latest block heights for each peer.
func (*Server) WaitForShutdown ¶
func (server *Server) WaitForShutdown()
WaitForShutdown blocks until the main listener and peer handlers are stopped.
type UpdatePeerHeightsMsg ¶
UpdatePeerHeightsMsg is a message sent from the blockmanager to the server after a new block has been accepted. The purpose of the message is to update the heights of peers that were known to announce the block before we connected it to the main BlockChain or recognized it as an orphan. With these updates, peer heights will be kept up to date, allowing for fresh data when selecting sync peer candidacy.