network

package
v0.0.0-...-1904e56 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolID       = "/p2p-file-sharing/1.0.0"
	FileRequestType  = "file-request"
	FileResponseType = "file-response"
	ChunkSize        = 1024 * 1024 // 1MB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressExchangeRequest

type AddressExchangeRequest struct {
	PeerID string `json:"peer_id"`
}

AddressExchangeRequest представляет запрос на обмен адресами

type AddressExchangeResponse

type AddressExchangeResponse struct {
	Status    string   `json:"status"`
	Addresses []string `json:"addresses"`
}

AddressExchangeResponse представляет ответ на запрос обмена адресами

type FileRequest

type FileRequest struct {
	Hash string `json:"hash"`
}

type FileResponse

type FileResponse struct {
	Hash   string `json:"hash"`
	Size   int64  `json:"size"`
	Chunks int    `json:"chunks"`
	Error  string `json:"error,omitempty"`
}

type Message

type Message struct {
	Type    string          `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

type Node

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

Node представляет P2P узел в сети

func NewNode

func NewNode(ctx context.Context, shareDir string) (*Node, error)

NewNode создает новый P2P узел

func (*Node) Connect

func (n *Node) Connect(addr multiaddr.Multiaddr) error

Connect подключается к удаленному пиру

func (*Node) DHT

func (n *Node) DHT() *dht.IpfsDHT

DHT возвращает DHT узла

func (*Node) FindFileProviders

func (n *Node) FindFileProviders(ctx context.Context, hash string) ([]peer.ID, error)

FindFileProviders ищет пиров, у которых есть файл

func (*Node) Host

func (n *Node) Host() host.Host

Host возвращает libp2p хост

func (*Node) PublishFileInfo

func (n *Node) PublishFileInfo(ctx context.Context, hash string) error

PublishFileInfo публикует информацию о файле в DHT

func (*Node) RequestFile

func (n *Node) RequestFile(ctx context.Context, p peer.ID, hash string) (io.ReadCloser, error)

RequestFile запрашивает файл у пира

func (*Node) SetupAddressExchangeProtocol

func (n *Node) SetupAddressExchangeProtocol()

SetupAddressExchangeProtocol настраивает протокол обмена файлами

func (*Node) SetupProtocol

func (n *Node) SetupProtocol()

SetupProtocol настраивает протокол обмена файлами

func (*Node) Start

func (n *Node) Start() error

Start запускает узел и подключается к P2P сети

func (*Node) Stop

func (n *Node) Stop() error

Stop останавливает узел

Jump to

Keyboard shortcuts

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