networking/

directory
v0.0.0-...-28b05a4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: GPL-2.0

README

Networking Packages

These are packages supporting both the inter-node networking and the Xnode overlay network.

Package p2p

This is the library implemented P2P networking based on libp2p.

Instance Initialisation
// Construct and start a p2p instance
ins, err := p2p.NewInstance(cancelContext).SetP2PHost(existingHost).Build()
err = ins.Start()
Gossip Publish-and-Subscribe (pub-sub)
// Join the specific topic
err := ins.Join("topic")

// Publisher sample usage
err = ins.Publish("topic", []byte("message"))

// Subscriber sample usage
msg, err := s.Subscribe(topic)
go func() {
    for {
        select {
        case <-cancelContext.Done():
            return
        case m := <-msg:
            // Handle message......
        }
    }
}()
DHT (Distributed Hash Table)
// Add a key to DHT
err := ins.DHT.PutValue(timeoutCtx, "key", []byte("value"))

// Get a value from DHT
value, err := ins.DHT.GetValue(timeoutCtx, "key")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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