network

package
v0.0.0-...-14be240 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PeerInfoFilePath      = "/home/prapti_shah/peer_info.json"
	PeerConnectionTimeout = 30 * time.Second
)
View Source
const MessageProtocol = "/keeper/message/1.0.0"

Variables

View Source
var KeeperConfigs = map[string]string{
	"Frodo":  "/ip4/127.0.0.1/tcp/3000",
	"Sam":    "/ip4/127.0.0.1/tcp/3001",
	"Merry":  "/ip4/127.0.0.1/tcp/3002",
	"Pippin": "/ip4/127.0.0.1/tcp/3003",
}

Functions

func LoadPeerInfo

func LoadPeerInfo() (map[string]PeerInfo, error)

LoadPeerInfo loads peer information from the JSON file

func SetupP2P

func SetupP2P(ctx context.Context, config P2PConfig) (host.Host, error)

SetupP2P creates and configures a libp2p host

Types

type Discovery

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

func NewDiscovery

func NewDiscovery(ctx context.Context, h host.Host, name string) *Discovery

func (*Discovery) ConnectToPeer

func (d *Discovery) ConnectToPeer(info PeerInfo) (peer.ID, error)

ConnectToPeer connects to a specific peer

func (*Discovery) SavePeerInfo

func (d *Discovery) SavePeerInfo() error

SavePeerInfo saves peer information to a JSON file

type Message

type Message struct {
	From      string      `json:"from"`
	To        string      `json:"to"`
	Content   interface{} `json:"content"`
	Type      string      `json:"type"`
	Timestamp string      `json:"timestamp"`
}

type Messaging

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

func NewMessaging

func NewMessaging(h host.Host, name string) *Messaging

func (*Messaging) GetHost

func (m *Messaging) GetHost() host.Host

func (*Messaging) InitMessageHandling

func (m *Messaging) InitMessageHandling(onMessage func(Message))

func (*Messaging) SendMessage

func (m *Messaging) SendMessage(to string, peerID peer.ID, content interface{}) error

type P2PConfig

type P2PConfig struct {
	Name    string
	Address string
}

type PeerInfo

type PeerInfo struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

Jump to

Keyboard shortcuts

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