Documentation ¶
Index ¶
- Constants
- Variables
- func LoadNetworkKeyFromFile(path string) (libcrypto.PrivKey, error)
- func LoadOrNewNetworkKey(cfg *medletpb.Config) (libcrypto.PrivKey, error)
- func MarshalNetworkKey(key libcrypto.PrivKey) (string, error)
- func PeerInfoToProto(p peerstore.PeerInfo) *netpb.PeerInfo
- func PeersToProto(peers ...peerstore.PeerInfo) []*netpb.PeerInfo
- func UnmarshalNetworkKey(data string) (libcrypto.PrivKey, error)
- type BloomFilter
- type BootstrapConfig
- type ChainSyncPeersFilter
- type Dispatcher
- type MedService
- func (ms *MedService) Broadcast(msgType string, data []byte, priority int)
- func (ms *MedService) ClosePeer(peerID string, reason error)
- func (ms *MedService) Deregister(subscribers ...*Subscriber)
- func (ms *MedService) Node() *Node
- func (ms *MedService) Register(subscribers ...*Subscriber)
- func (ms *MedService) RequestAndResponse(ctx context.Context, query Query, f MessageCallback, ...) (bool, []error)
- func (ms *MedService) SendMessageToPeer(msgType string, data []byte, priority int, peerID string)
- func (ms *MedService) SendMessageToPeers(msgType string, data []byte, priority int, filter PeerFilterAlgorithm) []string
- func (ms *MedService) SendPbMessageToPeer(msgType string, pb proto.Message, priority int, peerID string)
- func (ms *MedService) SendPbMessageToPeers(msgType string, pb proto.Message, priority int, filter PeerFilterAlgorithm) []string
- func (ms *MedService) Start(ctx context.Context) error
- type Message
- type MessageCallback
- type MessageWeight
- type Node
- func (node *Node) Addrs() []multiaddr.Multiaddr
- func (node *Node) Bootstrap()
- func (node *Node) BroadcastMessage(msgType string, data []byte, priority int)
- func (node *Node) ClosePeer(peerID string, reason error)
- func (node *Node) Connected() []peer.ID
- func (node *Node) DHT() *dht.IpfsDHT
- func (node *Node) DHTSync()
- func (node *Node) EstablishedPeersCount() int32
- func (node *Node) PeersCount() int32
- func (node *Node) SaveCache()
- func (node *Node) SendMessageToPeer(msgType string, data []byte, priority int, peerID string)
- func (node *Node) SendMessageToPeers(msgType string, data []byte, priority int, filter PeerFilterAlgorithm) (peers []string)
- func (node *Node) Start(ctx context.Context) error
- type PeerFilterAlgorithm
- type Query
- type RandomPeerFilter
- type RecvMessage
- type SendMessage
- type Service
- type Subscriber
Constants ¶
const ( DefaultConnMgrHighWater = 900 DefaultConnMgrLowWater = 600 DefaultConnMgrGracePeriod = time.Second * 20 DefaultMaxReadConcurrency = 100 DefaultMaxWriteConcurrency = 100 )
DefaultConnMgrHighWater is the default value for the connection managers values from "ipfs/go-ipfs-config"
const ( MaxMessageSize = inet.MessageSizeMax StreamTTL = 10 * time.Second )
Network system parameters
const ( MessagePriorityHigh = iota MessagePriorityNormal MessagePriorityLow )
Message Priority.
const ( DefaultPrivateKeyFile = "network.key" DefaultBootstrapPeriod = 30 * time.Second DefaultCacheFile = "network.cache" DefaultCachePeriod = 3 * time.Minute )
Default Config
const ( MedProtocolID = "/med/1.0.0" MedDHTProtocolID = "/med/kad/1.0.0" )
Protocols
const ( MessageWeightZero = MessageWeight(0) MessageWeightNewTx MessageWeightNewBlock = MessageWeight(0.5) MessageWeightRouteTable MessageWeightChainChunks MessageWeightChainChunkData )
const
Variables ¶
var ( ErrNoPeersToSendMessage = errors.New("filtered peer connection does not existed") ErrContextDone = errors.New("context is done") )
Error types
var ( ErrListenPortIsNotAvailable = errors.New("listen port is not available") ErrConfigLackNetWork = errors.New("config.conf should have network") )
Errors
Functions ¶
func LoadNetworkKeyFromFile ¶
LoadNetworkKeyFromFile load network priv key from file.
func LoadOrNewNetworkKey ¶
LoadOrNewNetworkKey load network priv key from file or create new one.
func MarshalNetworkKey ¶
MarshalNetworkKey marshal network key.
func PeerInfoToProto ¶
PeerInfoToProto convert peerinfo to peerinfo for config file
func PeersToProto ¶
PeersToProto convert peers to peer list for config
Types ¶
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter manages bloom filter
func NewBloomFilter ¶
func NewBloomFilter(m uint, k uint, maxCount int) *BloomFilter
NewBloomFilter returns BloomFilter
func (*BloomFilter) HasKey ¶
func (bf *BloomFilter) HasKey(key string) bool
HasKey use bloom filter to check if the key exists quickly
func (*BloomFilter) HasRecvMessage ¶
func (bf *BloomFilter) HasRecvMessage(msg *SendMessage) bool
HasRecvMessage use bloom filter sender check if the key exists quickly
func (*BloomFilter) RecordKey ¶
func (bf *BloomFilter) RecordKey(key string)
RecordKey add key to bloom filter.
func (*BloomFilter) RecordRecvMessage ¶
func (bf *BloomFilter) RecordRecvMessage(msg *RecvMessage)
RecordRecvMessage records received message
type BootstrapConfig ¶
type BootstrapConfig struct { MinConnThreshold uint32 Period time.Duration ConnectionTimeout time.Duration BootstrapPeers []pstore.PeerInfo // seed host }
BootstrapConfig is a struct for bootstrapping node
func NewBootstrapConfig ¶
func NewBootstrapConfig(cfg *medletpb.Config) (bConfig *BootstrapConfig, err error)
NewBootstrapConfig return new BootstrapConfig
type ChainSyncPeersFilter ¶
type ChainSyncPeersFilter struct {
// contains filtered or unexported fields
}
ChainSyncPeersFilter will filter some peers randomly
func (*ChainSyncPeersFilter) Filter ¶
func (filter *ChainSyncPeersFilter) Filter(peers []peer.ID) []peer.ID
Filter implements PeerFilterAlgorithm interface
func (*ChainSyncPeersFilter) SetExcludedPIDs ¶
func (filter *ChainSyncPeersFilter) SetExcludedPIDs(excludedPIDs map[string]struct{})
SetExcludedPIDs set excludedPIDs
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher a message dispatcher service.
func (*Dispatcher) Deregister ¶
func (dp *Dispatcher) Deregister(subscribers ...*Subscriber)
Deregister deregister subscribers.
func (*Dispatcher) ReceivedMessageCh ¶
func (dp *Dispatcher) ReceivedMessageCh() chan<- Message
ReceivedMessageCh return dispatcher's received message channel
func (*Dispatcher) Register ¶
func (dp *Dispatcher) Register(subscribers ...*Subscriber)
Register register subscribers.
func (*Dispatcher) Start ¶
func (dp *Dispatcher) Start(ctx context.Context)
Start start message dispatch goroutine.
type MedService ¶
type MedService struct {
// contains filtered or unexported fields
}
MedService service for medibloc p2p network
func NewNetService ¶
func NewNetService(cfg *medletpb.Config) (*MedService, error)
NewNetService create netService
func (*MedService) Broadcast ¶
func (ms *MedService) Broadcast(msgType string, data []byte, priority int)
Broadcast message.
func (*MedService) ClosePeer ¶
func (ms *MedService) ClosePeer(peerID string, reason error)
ClosePeer close connection
func (*MedService) Deregister ¶
func (ms *MedService) Deregister(subscribers ...*Subscriber)
Deregister Deregister the subscribers.
func (*MedService) Register ¶
func (ms *MedService) Register(subscribers ...*Subscriber)
Register register the subscribers.
func (*MedService) RequestAndResponse ¶
func (ms *MedService) RequestAndResponse(ctx context.Context, query Query, f MessageCallback, filter PeerFilterAlgorithm) (bool, []error)
RequestAndResponse set id to query and send to peers
func (*MedService) SendMessageToPeer ¶
func (ms *MedService) SendMessageToPeer(msgType string, data []byte, priority int, peerID string)
SendMessageToPeer send message to a peer.
func (*MedService) SendMessageToPeers ¶
func (ms *MedService) SendMessageToPeers(msgType string, data []byte, priority int, filter PeerFilterAlgorithm) []string
SendMessageToPeers send message to peers.
func (*MedService) SendPbMessageToPeer ¶
func (ms *MedService) SendPbMessageToPeer(msgType string, pb proto.Message, priority int, peerID string)
SendPbMessageToPeer send protobuf message to peer
func (*MedService) SendPbMessageToPeers ¶
func (ms *MedService) SendPbMessageToPeers(msgType string, pb proto.Message, priority int, filter PeerFilterAlgorithm) []string
SendPbMessageToPeers send protobuf messages to filtered peers
type MessageCallback ¶
MessageCallback is a function for handle response message
type Node ¶
Node the host can be used as both the client and the server
func (*Node) BroadcastMessage ¶
BroadcastMessage broadcast message.
func (*Node) EstablishedPeersCount ¶
EstablishedPeersCount return handShakeSucceed steam count. Depreciated
func (*Node) PeersCount ¶
PeersCount return stream count. Depreciated
func (*Node) SaveCache ¶
func (node *Node) SaveCache()
SaveCache save host's peerstore to cache file
func (*Node) SendMessageToPeer ¶
SendMessageToPeer send message to a peer.
func (*Node) SendMessageToPeers ¶
func (node *Node) SendMessageToPeers(msgType string, data []byte, priority int, filter PeerFilterAlgorithm) (peers []string)
SendMessageToPeers send messages to filtered peers
type PeerFilterAlgorithm ¶
PeerFilterAlgorithm is the algorithm used to filter peers
type RandomPeerFilter ¶
type RandomPeerFilter struct {
N int
}
RandomPeerFilter will filter a peer randomly
type RecvMessage ¶
type RecvMessage struct {
// contains filtered or unexported fields
}
RecvMessage is a struct for received message
func (*RecvMessage) MessageFrom ¶
func (m *RecvMessage) MessageFrom() string
MessageFrom returns peer id of message sender
func (*RecvMessage) MessageType ¶
func (m *RecvMessage) MessageType() string
MessageType returns message type
type SendMessage ¶
type SendMessage struct {
// contains filtered or unexported fields
}
SendMessage is a struct for sending message
func (*SendMessage) MessageType ¶
func (m *SendMessage) MessageType() string
MessageType returns message type
func (*SendMessage) SetReceiver ¶
func (m *SendMessage) SetReceiver(receiver peer.ID)
SetReceiver sets receiver
type Service ¶
type Service interface { Start(ctx context.Context) error Node() *Node // dispatcher Register(...*Subscriber) Deregister(...*Subscriber) // host SendMessageToPeer(msgType string, data []byte, priority int, peerID string) SendMessageToPeers(msgType string, data []byte, priority int, filter PeerFilterAlgorithm) []string Broadcast(msgType string, data []byte, priority int) ClosePeer(peerID string, reason error) SendPbMessageToPeer(msgType string, pb proto.Message, priority int, peerID string) SendPbMessageToPeers(msgType string, pb proto.Message, priority int, filter PeerFilterAlgorithm) []string RequestAndResponse(ctx context.Context, query Query, f MessageCallback, filter PeerFilterAlgorithm) (bool, []error) }
Service net Service interface
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber subscriber.
func NewSubscriber ¶
func NewSubscriber(id interface{}, msgChan chan Message, doFilter bool, msgType string, weight MessageWeight) *Subscriber
NewSubscriber return new Subscriber instance.
func (*Subscriber) MessageChan ¶
func (s *Subscriber) MessageChan() chan Message
MessageChan return msgChan.
func (*Subscriber) MessageType ¶
func (s *Subscriber) MessageType() string
MessageType return msgTypes.
func (*Subscriber) MessageWeight ¶
func (s *Subscriber) MessageWeight() MessageWeight
MessageWeight return weight of msgType