Documentation ¶
Index ¶
- Constants
- Variables
- func NewP2pRequest(ctx context.Context, rType int, id []byte, addr string, msg proto.Message, ...) (req *p2pRequest)
- type ID
- func (*ID) Descriptor() ([]byte, []int)
- func (m *ID) GetId() []byte
- func (m *ID) GetPublicKey() []byte
- func (*ID) ProtoMessage()
- func (m *ID) Reset()
- func (m *ID) String() string
- func (m *ID) XXX_DiscardUnknown()
- func (m *ID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *ID) XXX_Merge(src proto.Message)
- func (m *ID) XXX_Size() int
- func (m *ID) XXX_Unmarshal(b []byte) error
- type P2PError
- type P2PInterface
- type P2PMessage
- type Package
- func (*Package) Descriptor() ([]byte, []int)
- func (m *Package) GetAnything() *any.Any
- func (m *Package) GetReplyFlag() bool
- func (m *Package) GetRequestNonce() uint64
- func (m *Package) GetSender() []byte
- func (m *Package) GetSignature() []byte
- func (*Package) ProtoMessage()
- func (m *Package) Reset()
- func (m *Package) String() string
- func (m *Package) XXX_DiscardUnknown()
- func (m *Package) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Package) XXX_Merge(src proto.Message)
- func (m *Package) XXX_Size() int
- func (m *Package) XXX_Unmarshal(b []byte) error
- type Ping
- func (*Ping) Descriptor() ([]byte, []int)
- func (m *Ping) GetCount() uint64
- func (*Ping) ProtoMessage()
- func (m *Ping) Reset()
- func (m *Ping) String() string
- func (m *Ping) XXX_DiscardUnknown()
- func (m *Ping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Ping) XXX_Merge(src proto.Message)
- func (m *Ping) XXX_Size() int
- func (m *Ping) XXX_Unmarshal(b []byte) error
- type Pong
- func (*Pong) Descriptor() ([]byte, []int)
- func (m *Pong) GetCount() uint64
- func (*Pong) ProtoMessage()
- func (m *Pong) Reset()
- func (m *Pong) String() string
- func (m *Pong) XXX_DiscardUnknown()
- func (m *Pong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Pong) XXX_Merge(src proto.Message)
- func (m *Pong) XXX_Size() int
- func (m *Pong) XXX_Unmarshal(b []byte) error
Constants ¶
View Source
const ( //NoDiscover means that p2p don't use any discover protocol NoDiscover = iota // 0 //GossipDiscover means that p2p use gossip as a discover protocol GossipDiscover )
Variables ¶
View Source
var ( ErrNoRemoteID = errors.New("remoteID is nil") ErrMsgOverSize = errors.New("header size check failed") ErrCasting = errors.New("casting failed") ErrDuplicateID = errors.New("remote ID is the same with local ID") ErrCanNotFindClient = errors.New("can't find client") ErrIdleTimeout = errors.New("idle timeout") )
Functions ¶
Types ¶
type ID ¶
type ID struct { // public_key of the peer (we no longer use the public key as the peer ID, but use it to verify messages) PublicKey []byte `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` // id is the computed hash of the public key Id []byte `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*ID) Descriptor ¶
func (*ID) GetPublicKey ¶
func (*ID) ProtoMessage ¶
func (*ID) ProtoMessage()
func (*ID) XXX_DiscardUnknown ¶
func (m *ID) XXX_DiscardUnknown()
func (*ID) XXX_Unmarshal ¶
type P2PInterface ¶
type P2PInterface interface { GetIP() net.IP GetID() []byte SetPort(port string) GetPort() string Listen() error Join(bootstrapIp []string) (num int, err error) DisConnectTo(id []byte) error Leave() Request(ctx context.Context, id []byte, m proto.Message) (msg P2PMessage, err error) Reply(ctx context.Context, id []byte, nonce uint64, m proto.Message) (err error) SubscribeEvent() (subID int, outch chan discover.P2PEvent, err error) UnSubscribeEvent(int) SubscribeMsg(chanBuffer int, messages ...interface{}) (outch chan P2PMessage, err error) UnSubscribeMsg(messages ...interface{}) NumOfMembers() int MembersID() [][]byte RandomPeerIP() []string // contains filtered or unexported methods }
P2PInterface represents a p2p network
func CreateP2PNetwork ¶
func CreateP2PNetwork(id []byte, ip, port string, netType int) (P2PInterface, error)
CreateP2PNetwork creates a P2PInterface implementation , gets a public IP and generates a secret key
type P2PMessage ¶
type P2PMessage struct { Msg ptypes.DynamicAny Sender []byte RequestNonce uint64 }
P2PMessage is a struct that includes message,sender and nonce
type Package ¶
type Package struct { Anything *any.Any `protobuf:"bytes,1,opt,name=anything,proto3" json:"anything,omitempty"` Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` // Sender's address and public key. Sender []byte `protobuf:"bytes,3,opt,name=sender,proto3" json:"sender,omitempty"` // request_nonce is the request/response ID. Null if ID associated to a message is not a request/response. RequestNonce uint64 `protobuf:"varint,4,opt,name=request_nonce,json=requestNonce,proto3" json:"request_nonce,omitempty"` // reply_flag indicates this is a reply to a request ReplyFlag bool `protobuf:"varint,5,opt,name=reply_flag,json=replyFlag,proto3" json:"reply_flag,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Package) Descriptor ¶
func (*Package) GetAnything ¶
func (*Package) GetReplyFlag ¶
func (*Package) GetRequestNonce ¶
func (*Package) GetSignature ¶
func (*Package) ProtoMessage ¶
func (*Package) ProtoMessage()
func (*Package) XXX_DiscardUnknown ¶
func (m *Package) XXX_DiscardUnknown()
func (*Package) XXX_Marshal ¶
func (*Package) XXX_Unmarshal ¶
type Ping ¶
type Ping struct { Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Ping) Descriptor ¶
func (*Ping) ProtoMessage ¶
func (*Ping) ProtoMessage()
func (*Ping) XXX_DiscardUnknown ¶
func (m *Ping) XXX_DiscardUnknown()
func (*Ping) XXX_Unmarshal ¶
type Pong ¶
type Pong struct { Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Pong) Descriptor ¶
func (*Pong) ProtoMessage ¶
func (*Pong) ProtoMessage()
func (*Pong) XXX_DiscardUnknown ¶
func (m *Pong) XXX_DiscardUnknown()
func (*Pong) XXX_Unmarshal ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.