Help us shape the future of Go! Take the 2026 Go Developer Survey

p2p

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 26 Imported by: 8

Documentation

Index

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

func NewP2pRequest

func NewP2pRequest(ctx context.Context, rType int, id []byte, addr string, msg proto.Message, nonce uint64) (req *p2pRequest)

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) Descriptor() ([]byte, []int)

func (*ID) GetId

func (m *ID) GetId() []byte

func (*ID) GetPublicKey

func (m *ID) GetPublicKey() []byte

func (*ID) ProtoMessage

func (*ID) ProtoMessage()

func (*ID) Reset

func (m *ID) Reset()

func (*ID) String

func (m *ID) String() string

func (*ID) XXX_DiscardUnknown

func (m *ID) XXX_DiscardUnknown()

func (*ID) XXX_Marshal

func (m *ID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ID) XXX_Merge

func (dst *ID) XXX_Merge(src proto.Message)

func (*ID) XXX_Size

func (m *ID) XXX_Size() int

func (*ID) XXX_Unmarshal

func (m *ID) XXX_Unmarshal(b []byte) error

type P2PError

type P2PError struct {
	// contains filtered or unexported fields
}

func (*P2PError) Error

func (e *P2PError) Error() string

func (*P2PError) Format

func (e *P2PError) Format(f fmt.State, c rune)

func (*P2PError) FormatError

func (e *P2PError) FormatError(p errors.Printer) error

func (*P2PError) Unwrap

func (e *P2PError) Unwrap() error

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) Descriptor() ([]byte, []int)

func (*Package) GetAnything

func (m *Package) GetAnything() *any.Any

func (*Package) GetReplyFlag

func (m *Package) GetReplyFlag() bool

func (*Package) GetRequestNonce

func (m *Package) GetRequestNonce() uint64

func (*Package) GetSender

func (m *Package) GetSender() []byte

func (*Package) GetSignature

func (m *Package) GetSignature() []byte

func (*Package) ProtoMessage

func (*Package) ProtoMessage()

func (*Package) Reset

func (m *Package) Reset()

func (*Package) String

func (m *Package) String() string

func (*Package) XXX_DiscardUnknown

func (m *Package) XXX_DiscardUnknown()

func (*Package) XXX_Marshal

func (m *Package) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Package) XXX_Merge

func (dst *Package) XXX_Merge(src proto.Message)

func (*Package) XXX_Size

func (m *Package) XXX_Size() int

func (*Package) XXX_Unmarshal

func (m *Package) XXX_Unmarshal(b []byte) error

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) Descriptor() ([]byte, []int)

func (*Ping) GetCount

func (m *Ping) GetCount() uint64

func (*Ping) ProtoMessage

func (*Ping) ProtoMessage()

func (*Ping) Reset

func (m *Ping) Reset()

func (*Ping) String

func (m *Ping) String() string

func (*Ping) XXX_DiscardUnknown

func (m *Ping) XXX_DiscardUnknown()

func (*Ping) XXX_Marshal

func (m *Ping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Ping) XXX_Merge

func (dst *Ping) XXX_Merge(src proto.Message)

func (*Ping) XXX_Size

func (m *Ping) XXX_Size() int

func (*Ping) XXX_Unmarshal

func (m *Ping) XXX_Unmarshal(b []byte) error

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) Descriptor() ([]byte, []int)

func (*Pong) GetCount

func (m *Pong) GetCount() uint64

func (*Pong) ProtoMessage

func (*Pong) ProtoMessage()

func (*Pong) Reset

func (m *Pong) Reset()

func (*Pong) String

func (m *Pong) String() string

func (*Pong) XXX_DiscardUnknown

func (m *Pong) XXX_DiscardUnknown()

func (*Pong) XXX_Marshal

func (m *Pong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Pong) XXX_Merge

func (dst *Pong) XXX_Merge(src proto.Message)

func (*Pong) XXX_Size

func (m *Pong) XXX_Size() int

func (*Pong) XXX_Unmarshal

func (m *Pong) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis
Package nat implements NAT handling facilities
Package nat implements NAT handling facilities

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL