core

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 37 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SIZE_1KiB = 1024
	SIZE_1MiB = 1024 * SIZE_1KiB
	SIZE_1GiB = 1024 * SIZE_1MiB
)

byte size

View Source
const AllIpAddress = "0.0.0.0"
View Source
const BufferSize = 64 * SIZE_1KiB
View Source
const DataShards = 2
View Source
const DirMode = 0644
View Source
const FragmentSize = 8 * SIZE_1MiB
View Source
const LocalAddress = "127.0.0.1"
View Source
const ParShards = 1
View Source
const SegmentSize = 16 * SIZE_1MiB

Variables

This section is empty.

Functions

func ExtractIp4FromMultiaddr added in v0.0.2

func ExtractIp4FromMultiaddr(multiaddr string) (string, uint64, error)

func GetExternalIp added in v0.0.2

func GetExternalIp() (string, error)

Get external network ip

Types

type Node

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

Node type - Implementation of a P2P Host

func NewBasicNode

func NewBasicNode(multiaddr ma.Multiaddr, workspace string, privatekeypath string, bootpeers []string, cmgr connmgr.ConnManager) (*Node, error)

NewBasicNode constructs a new *Node

  multiaddr: listen addresses of p2p host
  workspace: service working directory
  privatekeypath: private key file
	  If it's empty, automatically created in the program working directory
	  If it's a directory, it will be created in the specified directory

func (*Node) AddAddrToPearstore

func (n *Node) AddAddrToPearstore(id peer.ID, addr ma.Multiaddr, t time.Duration)

func (*Node) AddMultiaddrToPearstore

func (n *Node) AddMultiaddrToPearstore(multiaddr string, t time.Duration) (peer.ID, error)

func (Node) Addrs

func (n Node) Addrs() []ma.Multiaddr

func (*Node) AuthenticateMessage

func (n *Node) AuthenticateMessage(message proto.Message, data *pb.MessageData) bool

Authenticate incoming p2p message message: a protobufs go data object data: common p2p message data

func (Node) Close

func (n Node) Close() error

func (Node) ConnManager

func (n Node) ConnManager() connmgr.ConnManager

func (Node) Connect

func (n Node) Connect(ctx context.Context, pi peer.AddrInfo) error

func (Node) EventBus

func (n Node) EventBus() event.Bus

func (Node) GetMuEvent added in v0.0.10

func (n Node) GetMuEvent() string

func (Node) ID

func (n Node) ID() peer.ID

func (Node) Multiaddr

func (n Node) Multiaddr() string

func (Node) Mux

func (n Node) Mux() protocol.Switch

func (Node) Network

func (n Node) Network() network.Network

func (*Node) NewMessageData

func (n *Node) NewMessageData(messageId string, gossip bool) *pb.MessageData

helper method - generate message data shared between all node's p2p protocols messageId: unique for requests, copied from request for responses

func (*Node) NewPeerStream added in v0.0.9

func (n *Node) NewPeerStream(id peer.ID, p protocol.ID) (network.Stream, error)

NewPeerStream

func (Node) NewStream

func (n Node) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)

func (Node) Peerstore

func (n Node) Peerstore() peerstore.Peerstore

func (Node) PrivatekeyPath

func (n Node) PrivatekeyPath() string

func (Node) PutMuEventCh added in v0.0.10

func (n Node) PutMuEventCh(peerid string)

func (Node) RemoveStreamHandler

func (n Node) RemoveStreamHandler(pid protocol.ID)

func (*Node) SendFile added in v0.0.9

func (n *Node) SendFile(ctx context.Context, id peer.ID, path string) error

func (*Node) SendMsgToStream added in v0.0.9

func (n *Node) SendMsgToStream(s network.Stream, msg []byte) error

SendMsgToStream

func (*Node) SendProtoMessage

func (n *Node) SendProtoMessage(id peer.ID, p protocol.ID, data proto.Message) error

helper method - writes a protobuf go data object to a network stream data: reference of protobuf go data object to send (not the object itself) s: network stream to write the data to

func (Node) SetStreamHandler

func (n Node) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)

func (Node) SetStreamHandlerMatch

func (n Node) SetStreamHandlerMatch(pid protocol.ID, m func(protocol.ID) bool, handler network.StreamHandler)

func (*Node) SignProtoMessage

func (n *Node) SignProtoMessage(message proto.Message) ([]byte, error)

sign an outgoing p2p message payload

func (*Node) StarFileTransferProtocol added in v0.0.9

func (n *Node) StarFileTransferProtocol()

func (Node) Workspace

func (n Node) Workspace() string

type P2P

type P2P interface {
	host.Host // lib-p2p host
	GetMuEvent() string
}

P2P is an object participating in a p2p network, which implements protocols or provides services. It handles requests like a Server, and issues requests like a Client. It is called Host because it is both Server and Client (and Peer may be confusing). It references libp2p: https://github.com/libp2p/go-libp2p

Jump to

Keyboard shortcuts

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