libp2p

package
v0.4.159 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Stream Protocols
	// Stream Protocol for Deployment Requests
	DepReqProtocolID = "/nunet/dms/depreq/0.0.3"

	// Stream Protocol for Chat
	ChatProtocolID = "/nunet/dms/chat/0.0.1"

	// Stream Protocol for File Transfer
	FileTransferProtocolID = "/nunet/dms/file/0.0.1"

	// Stream Protocol for Ping
	PingProtocolID = "/nunet/dms/ping/0.0.2"

	// Rendezvous Points
	// Team Rendezvous
	TeamRendezvous = "nunet-team"

	// Edge Rendezvous
	EdgeRendezvous = "nunet-edge"

	// Test Rendezvous
	TestRendezvous = "nunet-test"

	// Staging Rendezvous
	StagingRendezvous = "nunet-staging"

	// Prod Rendezvous
	ProdRendezvous = "nunet"
)
View Source
const (
	MsgDepResp   = "DepResp"
	MsgDepReq    = "DepReq"
	MsgJobStatus = "JobStatus"
	MsgLogStderr = "LogStderr"
	MsgLogStdout = "LogStdout"
)

Constants containing all message types happening between peers.

View Source
const (
	ContainerJobPending               = "pending"
	ContainerJobRunning               = "running"
	ContainerJobFinishedWithErrors    = "finished with errors"
	ContainerJobFinishedWithoutErrors = "finished without errors"
	ContainerJobFailed                = "failed"
)

constants for job status messaging

View Source
const (
	JobSubmitted = "job-submitted"
	JobFailed    = "job-failed"
	JobCompleted = "job-completed"
)

constants for job status actions

Variables

View Source
var (
	DepReqQueue = make(chan models.DeploymentRequest)
	DepResQueue = make(chan models.DeploymentResponse)

	JobLogStderrQueue = make(chan string)
	JobLogStdoutQueue = make(chan string)
	JobFailedQueue    = make(chan string)
	JobCompletedQueue = make(chan string)

	FileTransferQueue = make(chan IncomingFileTransfer)
)
View Source
var AFS *afero.Afero = &afero.Afero{Fs: FS}
View Source
var InboundDepReqStream network.Stream
View Source
var (

	// bootstrap peers provided by NuNet
	NuNetBootstrapPeers []multiaddr.Multiaddr
)
View Source
var OutboundDepReqStream network.Stream

Functions

func AcceptFileTransfer added in v0.4.159

func AcceptFileTransfer(ctx context.Context, incomingFileTransfer IncomingFileTransfer) (string, <-chan utils.IOProgress, error)

AcceptFileTransfer accepts the file transfer and returns a file path of location where file is written as well as the progress channel with info on how much data is transferred.

func AcceptPeerFileTransfer added in v0.4.159

func AcceptPeerFileTransfer(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Temporary wrapper around AcceptFileTransfer, adds WebSocket layer

func Bootstrap

func Bootstrap(ctx context.Context, node host.Host, idht *dht.IpfsDHT) error

func ChangeDeviceStatus added in v0.4.159

func ChangeDeviceStatus(status bool) error

func CheckOnboarding

func CheckOnboarding()

func CleanupOldPeers

func CleanupOldPeers()

Cleans up old peers from DHT

func CleanupPeer added in v0.4.159

func CleanupPeer(id peer.ID) error

DEBUG ONLY

func ClearIncomingChatRequests added in v0.4.159

func ClearIncomingChatRequests() error

func ClearIncomingFileRequests added in v0.4.159

func ClearIncomingFileRequests() error

func CreateChatStream added in v0.4.159

func CreateChatStream(ctx context.Context, id peer.ID) (network.Stream, error)

func DMSp2pSet added in v0.4.159

func DMSp2pSet(node host.Host, dht *dht.IpfsDHT)

XXX bad implementation - don't use. Temporary measure for routes_test calling HandleRequestService

func DefaultDepReqPeer

func DefaultDepReqPeer(ctx context.Context, id string) (string, error)

SUGGESTION: Define two functions SetDepReqPeer and GetDepReqPeer Current function have both SET and GET logic which make things confusing

func DeploymentUpdate

func DeploymentUpdate(msgType string, msg string, close bool) error

DeploymentUpdate is an auxilary function to send updates from one machine to another Args:

msgType: one of MsgDepResp, MsgDepReq, MsgDepReqUpdate, MsgJobStatus, MsgLogStderr, MsgLogStdout
msg:     message to send
inbound: true if the depReq was inbound (DMS is CP) or false if depReq was outbound (DMS is SP)
close:   true if the depReq stream needs to be closed after sending the message

func DeploymentUpdateListener

func DeploymentUpdateListener(stream network.Stream)

DeploymentUpdateListener listens for deployment response and service running status.

func DeviceStatus added in v0.4.159

func DeviceStatus() (bool, error)

func DumpDHT

func DumpDHT(ctx context.Context) ([]models.PeerData, error)

func DumpKademliaDHT

func DumpKademliaDHT(ctx context.Context) ([]models.PeerData, error)

DEBUG ONLY

func FetchAvailableResources

func FetchAvailableResources(node host.Host) []models.FreeResources

FetchAvailableResources returns AvailableResources on DHT.

func FetchMachines

func FetchMachines(node host.Host) models.Machines

FetchMachines returns Machines on DHT.

func FileReadStreamWrite added in v0.4.159

func FileReadStreamWrite(file *os.File, stream network.Stream, w io.Writer)

func GenerateKey

func GenerateKey(seed int64) (crypto.PrivKey, crypto.PubKey, error)

func GetConnections

func GetConnections() ([]models.Connection, error)

func GetDHTUpdates

func GetDHTUpdates(ctx context.Context)

Fetches peer info of peers from Kad-DHT and updates Peerstore.

func GetPrivateKey

func GetPrivateKey() (crypto.PrivKey, error)

func GetPublicKey

func GetPublicKey() (crypto.PubKey, error)

func IncomingFileTransferRequests added in v0.4.159

func IncomingFileTransferRequests() (string, error)

func InitiateTransferFile added in v0.4.159

func InitiateTransferFile(ctx context.Context, w http.ResponseWriter, r *http.Request, id peer.ID, path string) error

func IsDepReqStreamOpen

func IsDepReqStreamOpen() bool

func IsDepRespStreamOpen

func IsDepRespStreamOpen() bool

func JoinChat added in v0.4.159

func JoinChat(w http.ResponseWriter, r *http.Request, id int) error

func ListCheckpoints added in v0.4.159

func ListCheckpoints() ([]checkpoint, error)

func ListDHTPeers

func ListDHTPeers(ctx context.Context) ([]peer.ID, error)

func ListKadDHTPeers

func ListKadDHTPeers(ctx, reqCtx context.Context) ([]string, error)

func ListPeers

func ListPeers() ([]peer.AddrInfo, error)

func ManualDHTUpdate added in v0.4.159

func ManualDHTUpdate(ctx context.Context)

DEBUG ONLY

func NewHost

func NewHost(ctx context.Context, priv crypto.PrivKey, server bool) (host.Host, *dht.IpfsDHT, error)

func OldPing deprecated added in v0.4.159

func OldPing(ctx context.Context, h host.Host, target peer.ID) models.PingResult

Deprecated: Use Ping instead which returns a channel of ping results and a context cancel function OldPing manualy pings the given peer and returns the result which contains success/fail status, RTT and and error message if any.

func OldPingPeer added in v0.4.159

func OldPingPeer(ctx context.Context, target peer.ID) (bool, *models.PingResult)

DEBUG ONLY

func PeersWithAvailability added in v0.4.159

func PeersWithAvailability(peers []models.PeerData) []models.PeerData

Filter function which returns a slice of the PeerData struct containing peers that are available.

func PeersWithCardanoAllowed

func PeersWithCardanoAllowed(peers []models.PeerData) []models.PeerData

PeersWithCardanoAllowed is a filter function which returns a slice of PeerData based on allow_cardano metadata on peer.

func PeersWithGPU

func PeersWithGPU(peers []models.PeerData) []models.PeerData

PeersWithGPU is a filter function which returns a slice of PeerData based on has_gpu metadata on peer.

func PeersWithMatchingSpec

func PeersWithMatchingSpec(peers []models.PeerData, depReq models.DeploymentRequest) []models.PeerData

PeersWithMatchingSpec takes in a depReq which has minimum spec specified to run a job. Then it matches it against the peers available.

func Ping

func Ping(ctx context.Context, targetPeer peer.ID) (<-chan ping.Result, func())

Ping pings the given peer and returns the result along with the context cancel function

func PingHandler

func PingHandler(s network.Stream)

PingHandler handles an incoming ping. This implementation handles two protocols: 1. The old protocol for backward compatibility (/nunet/dms/ping/0.0.1) 2. The new protocol (/ipfs/ping/1.0.0) The old protocol will be deprecated soon.

func PingPeer

func PingPeer(ctx context.Context, target peer.ID) (bool, ping.Result)

DEBUG ONLY

func RemoveConnection

func RemoveConnection(conn models.Connection) error

func RunNode

func RunNode(priv crypto.PrivKey, server bool, available bool) error

func SaveNodeInfo

func SaveNodeInfo(priv crypto.PrivKey, pub crypto.PubKey, serverMode bool, available bool) error

func SendDeploymentRequest

func SendDeploymentRequest(ctx context.Context, depReq models.DeploymentRequest) (network.Stream, error)

func SendFileToPeer added in v0.4.159

func SendFileToPeer(ctx context.Context, peerID peer.ID, filePath string, transferType FileTransferType) (<-chan utils.IOProgress, error)

SendFileToPeer takes a libp2p peer id and a file path and sends the file to the peer.

func ShutdownNode added in v0.4.118

func ShutdownNode() error

func SockReadStreamWrite

func SockReadStreamWrite(conn *internal.WebSocketConnection, stream network.Stream, w *bufio.Writer)

func StartChat added in v0.4.159

func StartChat(w http.ResponseWriter, r *http.Request, s network.Stream, id string)

func StreamReadFileWrite added in v0.4.159

func StreamReadFileWrite(ctxDone context.CancelFunc, incomingFileTransfer IncomingFileTransfer, file *os.File, r io.Reader)

func StreamReadSockWrite

func StreamReadSockWrite(conn *internal.WebSocketConnection, stream network.Stream, r *bufio.Reader)

func UpdateConnections

func UpdateConnections(conns []network.Conn) error

UpdateConnections updates the database with the current connections.

func UpdateKadDHT

func UpdateKadDHT()

UpdateKadDHT updates the Kad-DHT with the current node's peer info

Types

type DMSp2p

type DMSp2p struct {
	Host host.Host
	DHT  *dht.IpfsDHT
	PS   peerstore.Peerstore
	// contains filtered or unexported fields
}

func DMSp2pInit

func DMSp2pInit(node host.Host, dht *dht.IpfsDHT) *DMSp2p

func GetP2P

func GetP2P() DMSp2p

func (DMSp2p) BootstrapNode

func (p2p DMSp2p) BootstrapNode(ctx context.Context) error

func (DMSp2p) StartDiscovery

func (p2p DMSp2p) StartDiscovery(ctx context.Context, rendezvous string)

type FileMetadata added in v0.4.159

type FileMetadata struct {
	Name           string           `json:"name"`
	Size           int64            `json:"size"`
	Mod            os.FileMode      `json:"mod"`
	SHA256Checksum string           `json:"sha256_checksum"`
	TransferType   FileTransferType `json:"transfer_type"`
}

type FileTransferResult added in v0.4.159

type FileTransferResult struct {
	FilePath     string
	TransferChan <-chan utils.IOProgress
	Error        error
}

type FileTransferType added in v0.4.159

type FileTransferType uint8
const (
	FTDEPREQ FileTransferType = 0 // depreq related file transfer
	FTMISC   FileTransferType = 1 // misc file transfer
)

type IncomingFileTransfer added in v0.4.159

type IncomingFileTransfer struct {
	ID                int
	File              FileMetadata
	Time              time.Time
	Sender            peer.ID
	SenderPublicKey   crypto.PubKey
	InboundFileStream network.Stream
}
var CurrentFileTransfer IncomingFileTransfer

type OpenStream added in v0.4.159

type OpenStream struct {
	ID         int    `json:"id"`
	StreamID   string `json:"stream_id"`
	FromPeer   string `json:"from_peer"`
	TimeOpened string `json:"time_opened"`
}

func IncomingChatRequests added in v0.4.159

func IncomingChatRequests() ([]OpenStream, error)

type SelfPeer added in v0.4.159

type SelfPeer struct {
	ID    string
	Addrs []multiaddr.Multiaddr
}

TODO: Move this struct somewhere else

func SelfPeerInfo

func SelfPeerInfo() (*SelfPeer, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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