core

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 43 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 (
	FileType_ServiceFile uint32 = iota
	FileType_IdleFile
	FileType_TagFile
	FileType_MusFile
	FileType_UsFile
	FileType_NamesFile
)
View Source
const (
	//
	FileDataDirectionry   = "file"
	TmpDataDirectionry    = "tmp"
	IdleDataDirectionry   = "space"
	IdleTagDirectionry    = "itag"
	ServiceTagDirectionry = "stag"
	ProofDirectionry      = "proof"
	//
	IdleProofFile    = "iproof"
	ServiceProofFile = "sproof"
)
View Source
const AggrProof_PROTOCOL = "/kldr/apv/1"
View Source
const AllIpAddress = "0.0.0.0"
View Source
const BufferSize = 64 * SIZE_1KiB
View Source
const CustomDataTag_Protocol = "/kldr/cdtg/1"
View Source
const DataShards = 2
View Source
const DirMode = 0644
View Source
const FILE_PROTOCOL = "/kldr/kft/1"
View Source
const FileProtocolBufSize = 2 * 1024 * 1024
View Source
const FileProtocolMsgBuf = 16 * 1024 * 1024
View Source
const FragmentSize = 8 * SIZE_1MiB
View Source
const IdleDataTag_Protocol = "/kldr/idtg/1"
View Source
const IdleProtocolMsgBuf = 1024
View Source
const LocalAddress = "127.0.0.1"
View Source
const MaxCustomDataLength = 255
View Source
const MaxFileNameLength = 255
View Source
const MusProtocolMsgBuf = 32
View Source
const P2PReadReqRespTime = time.Duration(time.Second * 15)
View Source
const P2PResponseFailed uint32 = 400
View Source
const P2PResponseFinish uint32 = 210
View Source
const P2PResponseOK uint32 = 200
View Source
const P2PWriteReqRespTime = time.Duration(time.Second * 15)
View Source
const ParShards = 1
View Source
const PushTag_Protocol = "/kldr/tagpush/1"
View Source
const Rendezvous = "/rendezvous/1.0.0"
View Source
const SegmentSize = 16 * SIZE_1MiB
View Source
const TagProtocolMsgBuf = 1024 * 1024

Variables

View Source
var (
	FileNameLengthErr   = fmt.Errorf("filename length exceeds %d", MaxFileNameLength)
	FileNameEmptyErr    = fmt.Errorf("filename is empty")
	CustomDataLengthErr = fmt.Errorf("custom data length exceeds %d", MaxCustomDataLength)
)

Functions

func CalcFileSHA256 added in v0.0.24

func CalcFileSHA256(f *os.File) (string, error)

CalcFileSHA256 is used to calculate the sha256 value of the file type.

func CalcPathSHA256 added in v0.0.24

func CalcPathSHA256(fpath string) (string, error)

CalcPathSHA256 is used to calculate the sha256 value of a file with a given path.

func CalcSHA256 added in v0.0.24

func CalcSHA256(data []byte) (string, error)

CalcSHA256 is used to calculate the sha256 value of the data.

func NewProtocol added in v0.0.24

func NewProtocol() *protocols

Types

type AggrProofProtocol added in v0.0.24

type AggrProofProtocol struct {
	*Node
}

func (*AggrProofProtocol) AggrProofReq added in v0.0.24

func (e *AggrProofProtocol) AggrProofReq(peerId peer.ID, ihash, shash []byte, qslice []*pb.Qslice, puk, sign []byte) (uint32, error)

func (AggrProofProtocol) FileReq added in v0.0.24

func (e AggrProofProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (AggrProofProtocol) IdleReq added in v0.0.24

func (e AggrProofProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (AggrProofProtocol) ReadFileAction added in v0.0.24

func (e AggrProofProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (AggrProofProtocol) TagPushReq added in v0.0.24

func (e AggrProofProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (AggrProofProtocol) TagReq added in v0.0.24

func (e AggrProofProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (AggrProofProtocol) WriteFileAction added in v0.0.24

func (e AggrProofProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type CustomDataTagProtocol added in v0.0.24

type CustomDataTagProtocol struct {
	*Node
}

func (CustomDataTagProtocol) FileReq added in v0.0.24

func (e CustomDataTagProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (CustomDataTagProtocol) IdleReq added in v0.0.24

func (e CustomDataTagProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (CustomDataTagProtocol) ReadFileAction added in v0.0.24

func (e CustomDataTagProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (CustomDataTagProtocol) TagPushReq added in v0.0.24

func (e CustomDataTagProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (CustomDataTagProtocol) TagReq added in v0.0.24

func (e CustomDataTagProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (CustomDataTagProtocol) WriteFileAction added in v0.0.24

func (e CustomDataTagProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type DataDirs added in v0.0.24

type DataDirs struct {
	FileDir       string
	TmpDir        string
	IdleDataDir   string
	IdleTagDir    string
	ServiceTagDir string
	ProofDir      string
	IproofFile    string
	SproofFile    string
}

type DiscoveredPeer added in v0.0.24

type DiscoveredPeer struct {
	PeerID peer.ID
	Addr   ma.Multiaddr
}

type FileProtocol added in v0.0.24

type FileProtocol struct {
	*Node
}

func (FileProtocol) FileReq added in v0.0.24

func (e FileProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (FileProtocol) IdleReq added in v0.0.24

func (e FileProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (FileProtocol) ReadFileAction added in v0.0.24

func (e FileProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (FileProtocol) TagPushReq added in v0.0.24

func (e FileProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (FileProtocol) TagReq added in v0.0.24

func (e FileProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (FileProtocol) WriteFileAction added in v0.0.24

func (e FileProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type IdleDataTagProtocol added in v0.0.24

type IdleDataTagProtocol struct {
	*Node
}

func (IdleDataTagProtocol) FileReq added in v0.0.24

func (e IdleDataTagProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (IdleDataTagProtocol) IdleReq added in v0.0.24

func (e IdleDataTagProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (IdleDataTagProtocol) ReadFileAction added in v0.0.24

func (e IdleDataTagProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (IdleDataTagProtocol) TagPushReq added in v0.0.24

func (e IdleDataTagProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (IdleDataTagProtocol) TagReq added in v0.0.24

func (e IdleDataTagProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (IdleDataTagProtocol) WriteFileAction added in v0.0.24

func (e IdleDataTagProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type Node

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

Node type - Implementation of a P2P Host

func (*Node) AddMultiaddrToPearstore

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

func (*Node) Addrs

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

Returns the listen addresses of the Host

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

Close shuts down the host, its Network, and services.

func (*Node) ConnManager

func (n *Node) ConnManager() connmgr.ConnManager

ConnManager returns this hosts connection manager

func (*Node) Connect

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

Connect ensures there is a connection between this host and the peer with given peer.ID. Connect will absorb the addresses in pi into its internal peerstore. If there is not an active connection, Connect will issue a h.Network.Dial, and block until a connection is open, or an error is returned. // TODO: Relay + NAT.

func (*Node) DiscoveredPeer added in v0.0.24

func (n *Node) DiscoveredPeer() <-chan DiscoveredPeer

func (*Node) EventBus

func (n *Node) EventBus() event.Bus

EventBus returns the hosts eventbus

func (Node) FileReq added in v0.0.24

func (e Node) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (*Node) GetBootstraps added in v0.0.24

func (n *Node) GetBootstraps() []string

func (*Node) GetDhtProtocolVersion added in v0.0.24

func (n *Node) GetDhtProtocolVersion() string

func (*Node) GetDirs added in v0.0.24

func (n *Node) GetDirs() DataDirs

func (*Node) GetDiscoverSt added in v0.0.24

func (n *Node) GetDiscoverSt() bool

func (*Node) GetIdleDataCh added in v0.0.24

func (n *Node) GetIdleDataCh() <-chan string

func (*Node) GetIdleFileTee added in v0.0.15

func (n *Node) GetIdleFileTee() string

func (*Node) GetIdleTagCh added in v0.0.24

func (n *Node) GetIdleTagCh() <-chan string

func (*Node) GetOwnPublickey added in v0.0.24

func (n *Node) GetOwnPublickey() []byte

func (*Node) GetPeerIdFromPubkey added in v0.0.18

func (n *Node) GetPeerIdFromPubkey(pubkey []byte) (string, error)

func (*Node) GetProtocolVersion added in v0.0.24

func (n *Node) GetProtocolVersion() string

func (*Node) GetServiceFileTee added in v0.0.15

func (n *Node) GetServiceFileTee() string

func (*Node) GetServiceTagCh added in v0.0.24

func (n *Node) GetServiceTagCh() <-chan string

func (*Node) ID

func (n *Node) ID() peer.ID

ID returns the (local) peer.ID associated with this Host

func (Node) IdleReq added in v0.0.24

func (e Node) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (*Node) Multiaddr

func (n *Node) Multiaddr() string

func (*Node) Mux

func (n *Node) Mux() protocol.Switch

Mux returns the Mux multiplexing incoming streams to protocol handlers

func (*Node) Network

func (n *Node) Network() network.Network

Networks returns the Network interface of the Host

func (*Node) NewAggrProofProtocol added in v0.0.24

func (n *Node) NewAggrProofProtocol() *AggrProofProtocol

func (*Node) NewCustomDataTagProtocol added in v0.0.24

func (n *Node) NewCustomDataTagProtocol() *CustomDataTagProtocol

func (*Node) NewFileProtocol added in v0.0.24

func (n *Node) NewFileProtocol() *FileProtocol

func (*Node) NewIdleDataTagProtocol added in v0.0.24

func (n *Node) NewIdleDataTagProtocol() *IdleDataTagProtocol

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) NewPushTagProtocol added in v0.0.24

func (n *Node) NewPushTagProtocol() *PushTagProtocol

func (*Node) NewReadFileProtocol added in v0.0.24

func (n *Node) NewReadFileProtocol() *ReadFileProtocol

func (*Node) NewStream

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

NewStream opens a new stream to given peer p, and writes a p2p/protocol header with given ProtocolID. If there is no connection to p, attempts to create one. If ProtocolID is "", writes no header. (Threadsafe)

func (*Node) NewWriteFileProtocol added in v0.0.24

func (n *Node) NewWriteFileProtocol() *WriteFileProtocol

func (*Node) Peerstore

func (n *Node) Peerstore() peerstore.Peerstore

Peerstore returns the Host's repository of Peer Addresses and Keys.

func (*Node) PrivatekeyPath

func (n *Node) PrivatekeyPath() string

func (Node) ReadFileAction added in v0.0.24

func (e Node) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (*Node) RemoveStreamHandler

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

RemoveStreamHandler removes a handler on the mux that was set by SetStreamHandler

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) SetBootstraps added in v0.0.24

func (n *Node) SetBootstraps(bootstrap []string)

func (*Node) SetIdleFileTee added in v0.0.15

func (n *Node) SetIdleFileTee(peerid string)

func (*Node) SetServiceFileTee added in v0.0.15

func (n *Node) SetServiceFileTee(peerid string)

func (*Node) SetStreamHandler

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

SetStreamHandler sets the protocol handler on the Host's Mux. This is equivalent to: host.Mux().SetHandler(proto, handler) (Threadsafe)

func (*Node) SetStreamHandlerMatch

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

SetStreamHandlerMatch sets the protocol handler on the Host's Mux using a matching function for protocol selection.

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) StartDiscover added in v0.0.24

func (n *Node) StartDiscover()

func (Node) TagPushReq added in v0.0.24

func (e Node) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (Node) TagReq added in v0.0.24

func (e Node) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (*Node) Workspace

func (n *Node) Workspace() string

func (Node) WriteFileAction added in v0.0.24

func (e Node) WriteFileAction(id peer.ID, roothash, path string) error

type P2P

type P2P interface {
	host.Host // lib-p2p host
	Protocol  // protocol
	GetDiscoverSt() bool
	StartDiscover()
	PrivatekeyPath() string
	Workspace() string
	Multiaddr() string
	AddMultiaddrToPearstore(multiaddr string, t time.Duration) (peer.ID, error)
	GetPeerIdFromPubkey(pubkey []byte) (string, error)
	GetOwnPublickey() []byte
	GetProtocolVersion() string
	GetDhtProtocolVersion() string
	GetDirs() DataDirs
	GetBootstraps() []string
	SetBootstraps(bootstrap []string)
	DiscoveredPeer() <-chan DiscoveredPeer
	GetIdleDataCh() <-chan string
	GetIdleTagCh() <-chan string
	GetServiceTagCh() <-chan 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

func NewBasicNode

func NewBasicNode(
	ctx context.Context,
	port int,
	workspace string,
	protocolVersion string,
	dhtProtocolVersion string,
	privatekeypath string,
	bootstrap []string,
	cmgr connmgr.ConnManager,
) (P2P, 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

type ProofFileType added in v0.0.24

type ProofFileType struct {
	Names []string `json:"names"`
	Us    []string `json:"us"`
	Mus   []string `json:"mus"`
	Sigma string   `json:"sigma"`
}

type Protocol added in v0.0.24

type Protocol interface {
	WriteFileAction(id peer.ID, roothash, path string) error
	ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error
	TagPushReq(peerid peer.ID) (uint32, error)
	IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)
	TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)
	FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)
}

type PushTagProtocol added in v0.0.24

type PushTagProtocol struct {
	*Node
}

func (PushTagProtocol) FileReq added in v0.0.24

func (e PushTagProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (PushTagProtocol) IdleReq added in v0.0.24

func (e PushTagProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (PushTagProtocol) ReadFileAction added in v0.0.24

func (e PushTagProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (PushTagProtocol) TagPushReq added in v0.0.24

func (e PushTagProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (PushTagProtocol) TagReq added in v0.0.24

func (e PushTagProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (PushTagProtocol) WriteFileAction added in v0.0.24

func (e PushTagProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type ReadFileProtocol added in v0.0.24

type ReadFileProtocol struct {
	*Node // local host
	// contains filtered or unexported fields
}

func (ReadFileProtocol) FileReq added in v0.0.24

func (e ReadFileProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (ReadFileProtocol) IdleReq added in v0.0.24

func (e ReadFileProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (ReadFileProtocol) ReadFileAction added in v0.0.24

func (e ReadFileProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (ReadFileProtocol) TagPushReq added in v0.0.24

func (e ReadFileProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (ReadFileProtocol) TagReq added in v0.0.24

func (e ReadFileProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (ReadFileProtocol) WriteFileAction added in v0.0.24

func (e ReadFileProtocol) WriteFileAction(id peer.ID, roothash, path string) error

type WriteFileProtocol added in v0.0.24

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

func (WriteFileProtocol) FileReq added in v0.0.24

func (e WriteFileProtocol) FileReq(peerId peer.ID, filehash string, filetype pb.FileType, fpath string) (uint32, error)

func (WriteFileProtocol) IdleReq added in v0.0.24

func (e WriteFileProtocol) IdleReq(peerId peer.ID, filesize, blocknum uint64, pubkey, sign []byte) (uint32, error)

func (WriteFileProtocol) ReadFileAction added in v0.0.24

func (e WriteFileProtocol) ReadFileAction(id peer.ID, roothash, datahash, path string, size int64) error

func (WriteFileProtocol) TagPushReq added in v0.0.24

func (e WriteFileProtocol) TagPushReq(peerid peer.ID) (uint32, error)

remote peer requests handler

func (WriteFileProtocol) TagReq added in v0.0.24

func (e WriteFileProtocol) TagReq(peerId peer.ID, filename, customdata string, blocknum uint64) (uint32, error)

func (WriteFileProtocol) WriteFileAction added in v0.0.24

func (e WriteFileProtocol) WriteFileAction(id peer.ID, roothash, path string) error

Jump to

Keyboard shortcuts

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