Documentation ¶
Index ¶
- Constants
- Variables
- func ReadMsg(ctx context.Context, r msgio.ReadCloser, mes proto.Message) error
- func UpdateLogger()
- func WriteMsg(w io.Writer, mes proto.Message) error
- type ConnectionGater
- func (cg *ConnectionGater) BlockAddr(ip net.IP) error
- func (cg *ConnectionGater) BlockPeer(p peer.ID) error
- func (cg *ConnectionGater) IncreaseBanscore(p peer.ID, persistent, transient uint32) (bool, error)
- func (cg *ConnectionGater) InterceptAccept(cma network.ConnMultiaddrs) (allow bool)
- func (cg *ConnectionGater) InterceptAddrDial(p peer.ID, a ma.Multiaddr) (allow bool)
- func (cg *ConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)
- func (cg *ConnectionGater) InterceptSecured(dir network.Direction, p peer.ID, cma network.ConnMultiaddrs) (allow bool)
- func (cg *ConnectionGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
- func (cg *ConnectionGater) ListBlockedAddrs() []net.IP
- func (cg *ConnectionGater) ListBlockedPeers() []peer.ID
- func (cg *ConnectionGater) UnblockAddr(ip net.IP) error
- func (cg *ConnectionGater) UnblockPeer(p peer.ID) error
- type CtxMutex
- type DynamicBanScore
- type MessageSender
- type Network
- func (n *Network) BroadcastBlock(blk *blocks.XThinnerBlock) error
- func (n *Network) BroadcastTransaction(tx *transactions.Transaction) error
- func (n *Network) Close() error
- func (n *Network) ConnGater() *ConnectionGater
- func (n *Network) ConnManager() coreconmgr.ConnManager
- func (n *Network) Dht() *dht.IpfsDHT
- func (n *Network) Host() host.Host
- func (n *Network) IncreaseBanscore(p peer.ID, persistent, transient uint32)
- func (n *Network) Pubsub() *pubsub.PubSub
- func (n *Network) SubscribeBlocks() (*pubsub.Subscription, error)
- func (n *Network) SubscribeTransactions() (*pubsub.Subscription, error)
- type Option
- func BanDuration(duration time.Duration) Option
- func BlockValidator(validateBlock func(blk *blocks.XThinnerBlock, p peer.ID) error) Option
- func Datastore(ds repo.Datastore) Option
- func DisableNatPortMap() Option
- func ForceDHTServerMode() Option
- func ListenAddrs(addrs []string) Option
- func MaxBanscore(max uint32) Option
- func MaxMessageSize(maxMessageSize int) Option
- func MempoolValidator(acceptToMempool func(tx *transactions.Transaction) error) Option
- func Params(params *params.NetworkParams) Option
- func PrivateKey(privKey crypto.PrivKey) Option
- func SeedAddrs(addrs []string) Option
- func UserAgent(s string) Option
- func WithHost(host host.Host) Option
Constants ¶
const ( // Halflife defines the time (in seconds) by which the transient part // of the ban score decays to one half of it's original value. Halflife = 60 // Lifetime defines the maximum age of the transient part of the ban // score to be considered a non-zero score (in seconds). Lifetime = 1800 )
const ( BlockTopic = "blocks" TransactionsTopic = "transactions" RelayKey = "/ilx/relaypeers" )
Variables ¶
var ErrNetworkConfig = errors.New("network config error")
var ErrReadTimeout = fmt.Errorf("timed out reading response")
ErrReadTimeout is an error that occurs when no message is read within the timeout period.
Functions ¶
func UpdateLogger ¶
func UpdateLogger()
Types ¶
type ConnectionGater ¶
ConnectionGater implements a connection gater that allows the application to perform access control on incoming and outgoing connections. The difference between this and the libp2p BasicConnectionGater is this class provides a method for incrementally increasing a peer's banscore and bans them only for a specified duration.
func NewConnectionGater ¶
func NewConnectionGater(ds repo.Datastore, addrBook peerstore.AddrBook, banDuration time.Duration, maxBanscore uint32) (*ConnectionGater, error)
NewConnectionGater creates a new connection gater.
func (*ConnectionGater) BlockAddr ¶
func (cg *ConnectionGater) BlockAddr(ip net.IP) error
BlockAddr adds an IP address to the set of blocked addresses. Note: active connections to the IP address are not automatically closed.
func (*ConnectionGater) BlockPeer ¶
func (cg *ConnectionGater) BlockPeer(p peer.ID) error
BlockPeer adds a peer to the set of blocked peers. Note: active connections to the peer are not automatically closed.
func (*ConnectionGater) IncreaseBanscore ¶
IncreaseBanscore increases the ban score for a peer. If the score goes over maxBanscore then the peer will be banned as well as its IP addresses.
If persistent is non-zero the persistent score will never decrease. The transient score does decrease according to a decay function.
func (*ConnectionGater) InterceptAccept ¶
func (cg *ConnectionGater) InterceptAccept(cma network.ConnMultiaddrs) (allow bool)
func (*ConnectionGater) InterceptAddrDial ¶
func (*ConnectionGater) InterceptPeerDial ¶
func (cg *ConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)
func (*ConnectionGater) InterceptSecured ¶
func (cg *ConnectionGater) InterceptSecured(dir network.Direction, p peer.ID, cma network.ConnMultiaddrs) (allow bool)
func (*ConnectionGater) InterceptUpgraded ¶
func (cg *ConnectionGater) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason)
func (*ConnectionGater) ListBlockedAddrs ¶
func (cg *ConnectionGater) ListBlockedAddrs() []net.IP
ListBlockedAddrs return a list of blocked IP addresses
func (*ConnectionGater) ListBlockedPeers ¶
func (cg *ConnectionGater) ListBlockedPeers() []peer.ID
ListBlockedPeers return a list of blocked peers
func (*ConnectionGater) UnblockAddr ¶
func (cg *ConnectionGater) UnblockAddr(ip net.IP) error
UnblockAddr removes an IP address from the set of blocked addresses
func (*ConnectionGater) UnblockPeer ¶
func (cg *ConnectionGater) UnblockPeer(p peer.ID) error
UnblockPeer removes a peer from the set of blocked peers
type DynamicBanScore ¶
type DynamicBanScore struct {
// contains filtered or unexported fields
}
DynamicBanScore provides dynamic ban scores consisting of a persistent and a decaying component. The persistent score could be utilized to create simple additive banning policies similar to those found in other bitcoin node implementations.
The decaying score enables the creation of evasive logic which handles misbehaving peers (especially application layer DoS attacks) gracefully by disconnecting and banning peers attempting various kinds of flooding. DynamicBanScore allows these two approaches to be used in tandem.
Zero value: Values of type DynamicBanScore are immediately ready for use upon declaration.
func (*DynamicBanScore) Increase ¶
func (s *DynamicBanScore) Increase(persistent, transient uint32) uint32
Increase increases both the persistent and decaying scores by the values passed as parameters. The resulting score is returned.
This function is safe for concurrent access.
func (*DynamicBanScore) Int ¶
func (s *DynamicBanScore) Int() uint32
Int returns the current ban score, the sum of the persistent and decaying scores.
This function is safe for concurrent access.
func (*DynamicBanScore) Reset ¶
func (s *DynamicBanScore) Reset()
Reset set both persistent and decaying scores to zero.
This function is safe for concurrent access.
func (*DynamicBanScore) String ¶
func (s *DynamicBanScore) String() string
String returns the ban score as a human-readable string.
type MessageSender ¶
type MessageSender interface { // SendRequest sends a peer a message and waits for its response SendRequest(ctx context.Context, p peer.ID, req proto.Message, resp proto.Message) error // SendMessage sends a peer a message without waiting on a response SendMessage(ctx context.Context, p peer.ID, pmes proto.Message) error }
MessageSender handles sending wire protocol messages to a given peer
func NewMessageSender ¶
func NewMessageSender(h host.Host, protos ...protocol.ID) MessageSender
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
func (*Network) BroadcastBlock ¶
func (n *Network) BroadcastBlock(blk *blocks.XThinnerBlock) error
func (*Network) BroadcastTransaction ¶
func (n *Network) BroadcastTransaction(tx *transactions.Transaction) error
func (*Network) ConnGater ¶
func (n *Network) ConnGater() *ConnectionGater
func (*Network) ConnManager ¶
func (n *Network) ConnManager() coreconmgr.ConnManager
func (*Network) IncreaseBanscore ¶
func (*Network) SubscribeBlocks ¶
func (n *Network) SubscribeBlocks() (*pubsub.Subscription, error)
func (*Network) SubscribeTransactions ¶
func (n *Network) SubscribeTransactions() (*pubsub.Subscription, error)
type Option ¶
type Option func(cfg *config) error
Option is configuration option function for the Network
func BanDuration ¶
func BlockValidator ¶
func DisableNatPortMap ¶
func DisableNatPortMap() Option
func ForceDHTServerMode ¶
func ForceDHTServerMode() Option
ForceDHTServerMode forces the DHT to start in server mode. This is necessary if the node is a validator as they need to be publicly reachable.
func ListenAddrs ¶
func MaxBanscore ¶
func MaxMessageSize ¶
func MempoolValidator ¶
func MempoolValidator(acceptToMempool func(tx *transactions.Transaction) error) Option
func Params ¶
func Params(params *params.NetworkParams) Option