Documentation ¶
Index ¶
- Variables
- func EnsureIPv4(ipOrHost string) (string, error)
- func GetBroadcastMsg(ctx context.Context) (*pubsub.Message, bool)
- func GetUnicastStream(ctx context.Context) (net.Stream, bool)
- func Logger() *zap.Logger
- func SetLogger(l *zap.Logger)
- type Config
- type HandleBroadcast
- type HandleUnicast
- type Host
- func (h *Host) AddBroadcastPubSub(topic string, callback HandleBroadcast) error
- func (h *Host) AddUnicastPubSub(topic string, callback HandleUnicast) error
- func (h *Host) Addresses() []multiaddr.Multiaddr
- func (h *Host) Broadcast(topic string, data []byte) error
- func (h *Host) Close() error
- func (h *Host) Connect(ctx context.Context, target peerstore.PeerInfo) error
- func (h *Host) ConnectWithMultiaddr(ctx context.Context, ma multiaddr.Multiaddr) error
- func (h *Host) HostIdentity() string
- func (h *Host) Info() peerstore.PeerInfo
- func (h *Host) JoinOverlay(ctx context.Context)
- func (h *Host) Neighbors(ctx context.Context) ([]peerstore.PeerInfo, error)
- func (h *Host) OverlayIdentity() string
- func (h *Host) Unicast(ctx context.Context, target peerstore.PeerInfo, topic string, data []byte) error
- type LRUBlacklist
- type Option
- func ConnectTimeout(timout time.Duration) Option
- func ExternalHostName(externalHostName string) Option
- func ExternalPort(externalPort int) Option
- func Gossip() Option
- func HostName(hostName string) Option
- func MasterKey(masterKey string) Option
- func Port(port int) Option
- func SecureIO() Option
- func WithConnectionManagerConfig(lo, hi int, grace time.Duration) Option
- func WithRateLimit(rcfg RateLimitConfig) Option
- func WithRelay(relayType string) Option
- type RateLimitConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ HostName: "127.0.0.1", Port: 30001, ExternalHostName: "", ExternalPort: 30001, SecureIO: false, Gossip: false, ConnectTimeout: time.Minute, MasterKey: "", Relay: "disable", ConnLowWater: 200, ConnHighWater: 500, RateLimiterLRUSize: 1000, BlackListLRUSize: 1000, BlackListCleanupInterval: 600 * time.Second, ConnGracePeriod: 0, EnableRateLimit: false, RateLimit: DefaultRatelimitConfig, }
DefaultConfig is a set of default configs
var DefaultRatelimitConfig = RateLimitConfig{
GlobalUnicastAvg: 300,
GlobalUnicastBurst: 500,
PeerAvg: 300,
PeerBurst: 500,
}
DefaultRatelimitConfig is the default rate limit config
var ProtocolDHT protocol.ID = "/iotex/kad/1.0.0"
ProtocolDHT is the DHT protocol ID
Functions ¶
func EnsureIPv4 ¶
EnsureIPv4 returns an IPv4 address regardless the input is a IPv4 address or host name. If the host name has multiple IPv4 address be associated, a random one will be returned.
func GetBroadcastMsg ¶
GetBroadcastMsg retrieves *pubsub.Message from broadcast message context.
func GetUnicastStream ¶
GetUnicastStream retrieves net.Stream from unicast request context.
Types ¶
type Config ¶
type Config struct { HostName string `yaml:"hostName"` Port int `yaml:"port"` ExternalHostName string `yaml:"externalHostName"` ExternalPort int `yaml:"externalPort"` SecureIO bool `yaml:"secureIO"` Gossip bool `yaml:"gossip"` ConnectTimeout time.Duration `yaml:"connectTimeout"` MasterKey string `yaml:"masterKey"` Relay string `yaml:"relay"` // could be `active`, `nat`, `disable` ConnLowWater int `yaml:"connLowWater"` ConnHighWater int `yaml:"connHighWater"` RateLimiterLRUSize int `yaml:"rateLimiterLRUSize"` BlackListLRUSize int `yaml:"blackListLRUSize"` BlackListCleanupInterval time.Duration `yaml:"blackListCleanupInterval"` ConnGracePeriod time.Duration `yaml:"connGracePeriod"` EnableRateLimit bool `yaml:"enableRateLimit"` RateLimit RateLimitConfig `yaml:"rateLimit"` }
Config enumerates the configs required by a host
type HandleBroadcast ¶
HandleBroadcast defines the callback function triggered when a broadcast message reaches a host
type HandleUnicast ¶
HandleUnicast defines the callback function triggered when a unicast message reaches a host
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is the main struct that represents a host that communicating with the rest of the P2P networks
func (*Host) AddBroadcastPubSub ¶
func (h *Host) AddBroadcastPubSub(topic string, callback HandleBroadcast) error
AddBroadcastPubSub adds a broadcast topic that the host will pay attention to. This need to be called before using Connect/JoinOverlay. Otherwise, pubsub may not be aware of the existing overlay topology
func (*Host) AddUnicastPubSub ¶
func (h *Host) AddUnicastPubSub(topic string, callback HandleUnicast) error
AddUnicastPubSub adds a unicast topic that the host will pay attention to
func (*Host) Addresses ¶
func (h *Host) Addresses() []multiaddr.Multiaddr
Addresses returns the multi address
func (*Host) ConnectWithMultiaddr ¶
ConnectWithMultiaddr connects a peer given the multi address
func (*Host) HostIdentity ¶
HostIdentity returns the host identity string
func (*Host) JoinOverlay ¶
JoinOverlay triggers the host to join the DHT overlay
func (*Host) OverlayIdentity ¶
OverlayIdentity returns the overlay identity string
type LRUBlacklist ¶ added in v0.2.4
type LRUBlacklist struct {
// contains filtered or unexported fields
}
LRUBlacklist is a blacklist implementation using an LRU cache
func NewLRUBlacklist ¶ added in v0.2.4
func NewLRUBlacklist(cap int) (*LRUBlacklist, error)
NewLRUBlacklist creates a new LRUBlacklist with capacity cap
func (*LRUBlacklist) Contains ¶ added in v0.2.4
func (b *LRUBlacklist) Contains(p peer.ID) bool
Contains checks if the peer ID is in LRU
func (*LRUBlacklist) Remove ¶ added in v0.2.4
func (b *LRUBlacklist) Remove(p peer.ID)
Remove removes a peer ID
func (*LRUBlacklist) RemoveOldest ¶ added in v0.2.4
func (b *LRUBlacklist) RemoveOldest()
RemoveOldest removes the oldest peer ID
type Option ¶
Option defines the option function to modify the config for a host
func ConnectTimeout ¶
ConnectTimeout is the option to override the connect timeout
func ExternalHostName ¶
ExternalHostName is the option to set the host name or IP address seen from external
func ExternalPort ¶
ExternalPort is the option to set the port number seen from external
func WithConnectionManagerConfig ¶ added in v0.2.3
WithConnectionManagerConfig set configuration for connection manager.
func WithRateLimit ¶ added in v0.2.6
func WithRateLimit(rcfg RateLimitConfig) Option
WithRateLimit is to indicate limiting msg rate from peers