Documentation ¶
Index ¶
- Constants
- Variables
- func ChannelOfNetID(id int) string
- func Inspect(c module.Chain, informal bool) map[string]interface{}
- func NewBroadcastError(err error, bt module.BroadcastType) module.NetworkError
- func NewManager(c module.Chain, nt module.NetworkTransport, trustSeeds string, ...) module.NetworkManager
- func NewMulticastError(err error, role module.Role) module.NetworkError
- func NewPeerID(b []byte) module.PeerID
- func NewPeerIDFromAddress(a module.Address) module.PeerID
- func NewPeerIDFromPublicKey(k *crypto.PublicKey) module.PeerID
- func NewPeerIDFromString(s string) module.PeerID
- func NewTransport(address string, w module.Wallet, l log.Logger) module.NetworkTransport
- func NewUnicastError(err error, id module.PeerID) module.NetworkError
- type Authenticator
- func (a *Authenticator) GetSecureAeads(channel string) []SecureAeadSuite
- func (a *Authenticator) GetSecureSuites(channel string) []SecureSuite
- func (a *Authenticator) SetSecureAeads(channel string, sas []SecureAeadSuite) error
- func (a *Authenticator) SetSecureSuites(channel string, ss []SecureSuite) error
- func (a *Authenticator) Signature(content []byte) []byte
- func (a *Authenticator) VerifySignature(publicKey []byte, signature []byte, content []byte) (module.PeerID, error)
- type BytesSet
- type ChannelNegotiator
- type ChannelQueue
- type Counter
- type Dialer
- type Error
- type JoinRequest
- type JoinResponse
- type Listener
- type NetAddress
- type NetAddressSet
- func (s *NetAddressSet) Add(a NetAddress) bool
- func (s *NetAddressSet) Array() []NetAddress
- func (s *NetAddressSet) Clear()
- func (s *NetAddressSet) ClearAndAdd(args ...NetAddress)
- func (s *NetAddressSet) Contains(a NetAddress) bool
- func (s *NetAddressSet) ContainsByPeer(p *Peer) bool
- func (s *NetAddressSet) Map() map[NetAddress]string
- func (s *NetAddressSet) Merge(args ...NetAddress)
- func (s *NetAddressSet) PutByPeer(p *Peer) (old string, removed NetAddress)
- func (s *NetAddressSet) RemoveByPeer(p *Peer) bool
- type P2PConnectionRequest
- type P2PConnectionResponse
- type Packet
- type PacketPool
- type PacketReadWriter
- type PacketReader
- type PacketWriter
- type Peer
- func (p *Peer) Close(reason string) error
- func (p *Peer) CloseByError(err error) error
- func (p *Peer) CloseInfo() string
- func (p *Peer) ConnString() string
- func (p *Peer) ID() module.PeerID
- func (p *Peer) IsClosed() bool
- func (p *Peer) NetAddress() NetAddress
- func (p *Peer) ResetConn(conn net.Conn)
- func (p *Peer) String() string
- type PeerConnectionType
- type PeerDispatcher
- type PeerHandler
- type PeerIDSet
- func (s *PeerIDSet) Add(id module.PeerID) (r bool)
- func (s *PeerIDSet) Array() []module.PeerID
- func (s *PeerIDSet) Bytes() []byte
- func (s *PeerIDSet) ClearAndAdd(args ...module.PeerID)
- func (s *PeerIDSet) Contains(id module.PeerID) bool
- func (s *PeerIDSet) Merge(args ...module.PeerID)
- func (s *PeerIDSet) Remove(id module.PeerID) (r bool)
- func (s *PeerIDSet) Removes(args ...module.PeerID)
- type PeerPredicate
- type PeerRTT
- type PeerRoleFlag
- type PeerSet
- func (s *PeerSet) Add(p *Peer) bool
- func (s *PeerSet) AddWithPredicate(p *Peer, f PeerPredicate) bool
- func (s *PeerSet) Array() []*Peer
- func (s *PeerSet) Clear()
- func (s *PeerSet) Contains(p *Peer) bool
- func (s *PeerSet) Find(foundFunc func(p *Peer) bool) []*Peer
- func (s *PeerSet) GetBy(role PeerRoleFlag, has bool, in bool) []*Peer
- func (s *PeerSet) GetByID(id module.PeerID) *Peer
- func (s *PeerSet) GetByRole(r PeerRoleFlag, has bool) []*Peer
- func (s *PeerSet) HasNetAddresse(a NetAddress) bool
- func (s *PeerSet) HasNetAddresseAndIncomming(a NetAddress, in bool) bool
- func (s *PeerSet) Merge(args ...*Peer)
- func (s *PeerSet) NetAddresses() []NetAddress
- func (s *PeerSet) Remove(p *Peer) bool
- type PeerToPeer
- type PriorityQueue
- type QueryMessage
- type QueryResultMessage
- type Queue
- type RoleSet
- type RttMessage
- type SecureAead
- type SecureAeadSuite
- type SecureConn
- type SecureError
- type SecureRequest
- type SecureResponse
- type SecureSuite
- type Set
- func (s *Set) Add(v interface{}) bool
- func (s *Set) Array() interface{}
- func (s *Set) Clear()
- func (s *Set) Contains(v interface{}) bool
- func (s *Set) IsEmpty() bool
- func (s *Set) Len() int
- func (s *Set) Map() map[interface{}]interface{}
- func (s *Set) Merge(args ...interface{})
- func (s *Set) Remove(v interface{}) bool
- func (s *Set) Set(v interface{}, d interface{}) interface{}
- func (s *Set) String() string
- type SignatureRequest
- type SignatureResponse
- type TimestampPool
- type WeightQueue
Constants ¶
View Source
const ( SecureSuiteUnknown = iota SecureSuiteNone SecureSuiteTls SecureSuiteEcdhe )
View Source
const ( SecureAeadSuiteUnknown = iota SecureAeadSuiteChaCha20Poly1305 SecureAeadSuiteAes128Gcm SecureAeadSuiteAes256Gcm )
View Source
const ( SecureErrorNone = "" SecureErrorInvalid = "invalid" SecureErrorEstablished = "established" )
View Source
const ( AlreadyListenedError = errors.CodeNetwork + iota AlreadyClosedError AlreadyDialingError AlreadyRegisteredReactorError AlreadyRegisteredProtocolError NotRegisteredReactorError NotRegisteredProtocolError NotRegisteredRoleError NotAuthorizedError NotAvailableError NotStartedError QueueOverflowError DuplicatedPacketError DuplicatedPeerError )
View Source
const ( DefaultTransportNet = "tcp4" DefaultDialTimeout = 5 * time.Second DefaultReceiveQueueSize = 1000 DefaultPacketBufferSize = 4096 //bufio.defaultBufSize=4096 DefaultPacketPayloadMax = 1024 * 1024 DefaultPacketPoolNumBucket = 20 DefaultPacketPoolBucketLen = 500 DefaultDiscoveryPeriod = 2 * time.Second DefaultSeedPeriod = 3 * time.Second DefaultMinSeed = 1 DefaultAlternateSendPeriod = 1 * time.Second DefaultSendTimeout = 5 * time.Second DefaultSendQueueMaxPriority = 7 DefaultSendQueueSize = 1000 DefaultEventQueueSize = 100 DefaultFailureQueueSize = 100 DefaultPeerSendQueueSize = 1000 DefaultPeerPoolExpireSecond = 5 DefaultUncleLimit = 1 DefaultChildrenLimit = 10 DefaultNephewLimit = 10 DefaultPacketRewriteLimit = 10 DefaultPacketRewriteDelay = 100 * time.Millisecond DefaultRttAccuracy = 10 * time.Millisecond DefaultFailureNodeMin = 2 DefaultSelectiveFloodingAdd = 1 DefaultSimplePeerIDSize = 4 UsingSelectiveFlooding = true DefaultDuplicatedPeerTime = 1 * time.Second DefaultMaxRetryClose = 10 )
View Source
const (
LoggerFieldKeySubModule = "sub"
)
Variables ¶
View Source
var ( ErrAlreadyListened = errors.NewBase(AlreadyListenedError, "AlreadyListened") ErrAlreadyClosed = errors.NewBase(AlreadyClosedError, "AlreadyClosed") ErrAlreadyDialing = errors.NewBase(AlreadyDialingError, "AlreadyDialing") ErrAlreadyRegisteredReactor = errors.NewBase(AlreadyRegisteredReactorError, "AlreadyRegisteredReactor") ErrAlreadyRegisteredProtocol = errors.NewBase(AlreadyRegisteredProtocolError, "AlreadyRegisteredProtocol") ErrNotRegisteredReactor = errors.NewBase(NotRegisteredReactorError, "NotRegisteredReactor") ErrNotRegisteredProtocol = errors.NewBase(NotRegisteredProtocolError, "NotRegisteredProtocol") ErrNotRegisteredRole = errors.NewBase(NotRegisteredRoleError, "NotRegisteredRole") ErrNotAuthorized = errors.NewBase(NotAuthorizedError, "NotAuthorized") ErrNotAvailable = errors.NewBase(NotAvailableError, "NotAvailable") ErrNotStarted = errors.NewBase(NotStartedError, "NotStarted") ErrQueueOverflow = errors.NewBase(QueueOverflowError, "QueueOverflow") ErrDuplicatedPacket = errors.NewBase(DuplicatedPacketError, "DuplicatedPacket") ErrDuplicatedPeer = errors.NewBase(DuplicatedPeerError, "DuplicatedPeer") ErrIllegalArgument = errors.ErrIllegalArgument )
View Source
var ( PROTO_AUTH_KEY_REQ = module.ProtocolInfo(0x0100) PROTO_AUTH_KEY_RESP = module.ProtocolInfo(0x0200) PROTO_AUTH_SIGN_REQ = module.ProtocolInfo(0x0300) PROTO_AUTH_SIGN_RESP = module.ProtocolInfo(0x0400) PROTO_CHAN_JOIN_REQ = module.ProtocolInfo(0x0500) PROTO_CHAN_JOIN_RESP = module.ProtocolInfo(0x0600) PROTO_P2P_QUERY = module.ProtocolInfo(0x0700) PROTO_P2P_QUERY_RESULT = module.ProtocolInfo(0x0800) PROTO_P2P_CONN_REQ = module.ProtocolInfo(0x0900) PROTO_P2P_CONN_RESP = module.ProtocolInfo(0x0A00) PROTO_P2P_RTT_REQ = module.ProtocolInfo(0x0B00) PROTO_P2P_RTT_RESP = module.ProtocolInfo(0x0C00) )
View Source
var ( DefaultSecureEllipticCurve = elliptic.P256() DefaultSecureSuites = []SecureSuite{ SecureSuiteNone, SecureSuiteTls, SecureSuiteEcdhe, } DefaultSecureAeadSuites = []SecureAeadSuite{ SecureAeadSuiteChaCha20Poly1305, SecureAeadSuiteAes128Gcm, SecureAeadSuiteAes256Gcm, } DefaultSecureKeyLogWriter io.Writer )
View Source
var (
PROTO_CONTOL = module.ProtocolInfo(0x0000)
)
Functions ¶
func ChannelOfNetID ¶
func NewBroadcastError ¶
func NewBroadcastError(err error, bt module.BroadcastType) module.NetworkError
func NewManager ¶
func NewManager(c module.Chain, nt module.NetworkTransport, trustSeeds string, roles ...module.Role) module.NetworkManager
func NewMulticastError ¶
func NewMulticastError(err error, role module.Role) module.NetworkError
func NewPeerIDFromString ¶
func NewTransport ¶
func NewUnicastError ¶
func NewUnicastError(err error, id module.PeerID) module.NetworkError
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
func (*Authenticator) GetSecureAeads ¶
func (a *Authenticator) GetSecureAeads(channel string) []SecureAeadSuite
func (*Authenticator) GetSecureSuites ¶
func (a *Authenticator) GetSecureSuites(channel string) []SecureSuite
func (*Authenticator) SetSecureAeads ¶
func (a *Authenticator) SetSecureAeads(channel string, sas []SecureAeadSuite) error
func (*Authenticator) SetSecureSuites ¶
func (a *Authenticator) SetSecureSuites(channel string, ss []SecureSuite) error
func (*Authenticator) Signature ¶
func (a *Authenticator) Signature(content []byte) []byte
func (*Authenticator) VerifySignature ¶
type BytesSet ¶
type BytesSet struct { *Set // contains filtered or unexported fields }
func NewBytesSet ¶
type ChannelNegotiator ¶
type ChannelNegotiator struct {
// contains filtered or unexported fields
}
Negotiation map<channel, map<protocolHandler.name, {protocol, []subProtocol}>>
type ChannelQueue ¶
type ChannelQueue struct {
// contains filtered or unexported fields
}
func (*ChannelQueue) Pop ¶
func (q *ChannelQueue) Pop() context.Context
func (*ChannelQueue) Wait ¶
func (q *ChannelQueue) Wait() <-chan context.Context
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
TODO data-race mutex
type Error ¶
type JoinRequest ¶
type JoinRequest struct { Channel string Addr NetAddress }
type JoinResponse ¶
type JoinResponse struct { Channel string Addr NetAddress }
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func (*Listener) SetAddress ¶
type NetAddress ¶
type NetAddress string
func (NetAddress) Validate ¶ added in v0.9.1
func (na NetAddress) Validate() error
type NetAddressSet ¶
type NetAddressSet struct { *Set // contains filtered or unexported fields }
func NewNetAddressSet ¶
func NewNetAddressSet() *NetAddressSet
func (*NetAddressSet) Add ¶
func (s *NetAddressSet) Add(a NetAddress) bool
func (*NetAddressSet) Array ¶
func (s *NetAddressSet) Array() []NetAddress
func (*NetAddressSet) Clear ¶
func (s *NetAddressSet) Clear()
func (*NetAddressSet) ClearAndAdd ¶
func (s *NetAddressSet) ClearAndAdd(args ...NetAddress)
func (*NetAddressSet) Contains ¶
func (s *NetAddressSet) Contains(a NetAddress) bool
func (*NetAddressSet) ContainsByPeer ¶
func (s *NetAddressSet) ContainsByPeer(p *Peer) bool
func (*NetAddressSet) Map ¶
func (s *NetAddressSet) Map() map[NetAddress]string
func (*NetAddressSet) Merge ¶
func (s *NetAddressSet) Merge(args ...NetAddress)
func (*NetAddressSet) PutByPeer ¶
func (s *NetAddressSet) PutByPeer(p *Peer) (old string, removed NetAddress)
func (*NetAddressSet) RemoveByPeer ¶
func (s *NetAddressSet) RemoveByPeer(p *Peer) bool
type P2PConnectionRequest ¶
type P2PConnectionRequest struct {
ConnType PeerConnectionType
}
TODO timestamp or sequencenumber for validation (request,response pair)
type P2PConnectionResponse ¶
type P2PConnectionResponse struct { ReqConnType PeerConnectionType ConnType PeerConnectionType }
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
srcPeerId, castType, destInfo, TTL(0:unlimited)
func NewPacket ¶
func NewPacket(pi module.ProtocolInfo, spi module.ProtocolInfo, payload []byte) *Packet
type PacketPool ¶
type PacketPool struct {
// contains filtered or unexported fields
}
func NewPacketPool ¶
func NewPacketPool(numOfBucket uint8, lenOfBucket uint16) *PacketPool
func (*PacketPool) Clear ¶
func (p *PacketPool) Clear()
func (*PacketPool) Contains ¶
func (p *PacketPool) Contains(pkt *Packet) bool
func (*PacketPool) Put ¶
func (p *PacketPool) Put(pkt *Packet) bool
type PacketReadWriter ¶
type PacketReadWriter struct {
// contains filtered or unexported fields
}
func NewPacketReadWriter ¶
func NewPacketReadWriter() *PacketReadWriter
func (*PacketReadWriter) ReadPacket ¶
func (prw *PacketReadWriter) ReadPacket() (*Packet, error)
func (*PacketReadWriter) WritePacket ¶
func (prw *PacketReadWriter) WritePacket(pkt *Packet) error
type PacketReader ¶
func NewPacketReader ¶
func NewPacketReader(rd io.Reader) *PacketReader
NewReader returns a new Reader whose buffer has the default size.
func (*PacketReader) ReadPacket ¶
func (pr *PacketReader) ReadPacket() (pkt *Packet, e error)
func (*PacketReader) Reset ¶
func (pr *PacketReader) Reset(rd io.Reader)
type PacketWriter ¶
func NewPacketWriter ¶
func NewPacketWriter(w io.Writer) *PacketWriter
func (*PacketWriter) Flush ¶
func (pw *PacketWriter) Flush() error
func (*PacketWriter) Reset ¶
func (pw *PacketWriter) Reset(wr io.Writer)
func (*PacketWriter) WritePacket ¶
func (pw *PacketWriter) WritePacket(pkt *Packet) error
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func (*Peer) CloseByError ¶
func (*Peer) ConnString ¶
func (*Peer) NetAddress ¶
func (p *Peer) NetAddress() NetAddress
type PeerConnectionType ¶
type PeerConnectionType byte
type PeerDispatcher ¶
type PeerDispatcher struct {
// contains filtered or unexported fields
}
type PeerHandler ¶
type PeerHandler interface {
// contains filtered or unexported methods
}
type PeerIDSet ¶
type PeerIDSet struct { *Set // contains filtered or unexported fields }
func NewPeerIDSet ¶
func NewPeerIDSet() *PeerIDSet
func NewPeerIDSetFromBytes ¶
func (*PeerIDSet) ClearAndAdd ¶
type PeerPredicate ¶ added in v0.9.2
type PeerRTT ¶
type PeerRTT struct {
// contains filtered or unexported fields
}
func NewPeerRTT ¶
func NewPeerRTT() *PeerRTT
type PeerRoleFlag ¶
type PeerRoleFlag byte
PeerRoleFlag as BitFlag MSB[_,_,_,_,_,_,Root,Seed]LSB
func (*PeerRoleFlag) Has ¶
func (pr *PeerRoleFlag) Has(o PeerRoleFlag) bool
func (*PeerRoleFlag) SetFlag ¶
func (pr *PeerRoleFlag) SetFlag(o PeerRoleFlag)
func (*PeerRoleFlag) ToRoles ¶
func (pr *PeerRoleFlag) ToRoles() []module.Role
func (*PeerRoleFlag) UnSetFlag ¶
func (pr *PeerRoleFlag) UnSetFlag(o PeerRoleFlag)
type PeerSet ¶
type PeerSet struct { *Set // contains filtered or unexported fields }
func NewPeerSet ¶
func NewPeerSet() *PeerSet
func (*PeerSet) AddWithPredicate ¶ added in v0.9.2
func (s *PeerSet) AddWithPredicate(p *Peer, f PeerPredicate) bool
func (*PeerSet) HasNetAddresse ¶
func (s *PeerSet) HasNetAddresse(a NetAddress) bool
func (*PeerSet) HasNetAddresseAndIncomming ¶
func (s *PeerSet) HasNetAddresseAndIncomming(a NetAddress, in bool) bool
func (*PeerSet) NetAddresses ¶
func (s *PeerSet) NetAddresses() []NetAddress
type PeerToPeer ¶
type PeerToPeer struct {
// contains filtered or unexported fields
}
func (*PeerToPeer) IsStarted ¶
func (p2p *PeerToPeer) IsStarted() bool
func (*PeerToPeer) Send ¶
func (p2p *PeerToPeer) Send(pkt *Packet) error
func (*PeerToPeer) Start ¶
func (p2p *PeerToPeer) Start()
func (*PeerToPeer) Stop ¶
func (p2p *PeerToPeer) Stop()
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
func NewPriorityQueue ¶
func NewPriorityQueue(size int, maxPriority int) *PriorityQueue
func (*PriorityQueue) Close ¶
func (q *PriorityQueue) Close()
type QueryMessage ¶
type QueryMessage struct {
Role PeerRoleFlag
}
TODO timestamp or sequencenumber for validation (query,result pair)
type QueryResultMessage ¶
type QueryResultMessage struct { Role PeerRoleFlag Seeds []NetAddress Roots []NetAddress Children []NetAddress Nephews []NetAddress Message string }
type Queue ¶
type SecureAead ¶
type SecureAead struct {
// contains filtered or unexported fields
}
type SecureAeadSuite ¶
type SecureAeadSuite byte
func SecureAeadSuiteFromString ¶
func SecureAeadSuiteFromString(s string) SecureAeadSuite
func (SecureAeadSuite) String ¶
func (s SecureAeadSuite) String() string
type SecureConn ¶
func NewSecureConn ¶
func NewSecureConn(conn net.Conn, sa SecureAeadSuite, k *secureKey) (*SecureConn, error)
type SecureError ¶
type SecureError string
type SecureRequest ¶
type SecureRequest struct { Channel string SecureSuites []SecureSuite SecureAeadSuites []SecureAeadSuite SecureParam []byte }
type SecureResponse ¶
type SecureResponse struct { Channel string SecureSuite SecureSuite SecureAeadSuite SecureAeadSuite SecureParam []byte SecureError SecureError }
type SecureSuite ¶
type SecureSuite byte
func SecureSuiteFromString ¶
func SecureSuiteFromString(s string) SecureSuite
func (SecureSuite) String ¶
func (s SecureSuite) String() string
type SignatureRequest ¶
type SignatureResponse ¶
type TimestampPool ¶
type TimestampPool struct {
// contains filtered or unexported fields
}
func NewTimestampPool ¶
func NewTimestampPool(numOfBucket uint8) *TimestampPool
func (*TimestampPool) Clear ¶
func (p *TimestampPool) Clear()
func (*TimestampPool) Contains ¶
func (p *TimestampPool) Contains(k interface{}) bool
func (*TimestampPool) Put ¶
func (p *TimestampPool) Put(k interface{})
func (*TimestampPool) RemoveBefore ¶
func (p *TimestampPool) RemoveBefore(secondDuration int)
type WeightQueue ¶
type WeightQueue struct {
// contains filtered or unexported fields
}
func NewWeightQueue ¶
func NewWeightQueue(size int, nq int) *WeightQueue
func (*WeightQueue) Close ¶
func (q *WeightQueue) Close()
Click to show internal directories.
Click to hide internal directories.