p2p

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 15 Imported by: 0

README

xlibp2p

xlibp2p is an opinionated, easy-to-use P2P network stack for decentralized applications written in Go.

xlibp2p is made to be minimal, robust, developer-friendly, performant, secure, and cross-platform across multitudes of devices by making use of a small amount of well-tested, production-grade dependencies.

Usage

xlibp2p was intended to be used in Go projects that utilize Go modules. You may incorporate xlibp2p into your project as a library dependency by executing the following:

go get -u github.com/Away-Leo/libp2p

Examples

In examples folder, you can find a chat example to help you get started in using xlibp2p. The example helping you expand your knowledge about xlibp2p and p2p networks in general.

Contribute

If you'd like to contribute to xlibp2p please fork, fix, commit and send a pull request. Commits who do not comply with the coding standards are ignored (use gofmt!). If you send pull requests make absolute sure that you commit on the develop branch and that you do not merge to master. Commits that are directly based on master are simply ignored.

License

xlibp2p is released under the open source MIT license and is offered “AS IS” without warranty of any kind, express or implied. Any security provided by the XFS software depends in part on how it is used, configured, and deployed. xlibp2p is built upon many third-party libraries, xfs.tech makes no representation or guarantee that xlibp2p or any third-party libraries will perform as intended or will be free of errors, bugs or faulty code. Both may fail in large or small ways that could completely or partially limit functionality or compromise computer systems. If you use or implement xlibp2p, you do so at your own risk. In no event will xfs.tech be liable to any party for any damages whatsoever, even if it had been advised of the possibility of damage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendMsgData

func SendMsgData(p Peer, mType uint8, obj interface{}) error

Types

type Config

type Config struct {
	Nat            nat.Mapper
	ListenAddr     string
	Key            *ecdsa.PrivateKey
	Discover       bool
	NodeDBPath     string
	StaticNodes    []*discover.Node
	BootstrapNodes []*discover.Node
	MaxPeers       int
	Logger         log.Logger
	Encoder        encoder
}

Config Background network service configuration

type MessageReader

type MessageReader interface {
	Type() uint8                // message type
	Read(p []byte) (int, error) // read given data to buffer
	ReadAll() ([]byte, error)   // read all of messages
	RawReader() io.Reader       // read raw messages(include version and mType fields)
	DataReader() io.Reader      // read data of message
}

MessageReader interface defines type of message and reading methods, messageReader implements this interface.

func ReadMessage

func ReadMessage(reader io.Reader) (MessageReader, error)

ReadMessage reads message from other peer and returns MessageReader by header of message. message = version(1byte)+type(1byte)+length(4byte)+data

type Peer

type Peer interface {
	Is(flag int) bool
	ID() discover.NodeId
	Close()
	Run()
	CloseCh() chan struct{}
	Read(bs []byte) (int, error)
	WriteMessage(mType uint8, data []byte) error
	WriteMessageObj(mType uint8, data interface{}) error
	GetProtocolMsgCh() chan MessageReader
}

type Protocol

type Protocol interface {
	Run(p Peer) error
}

type Server

type Server interface {
	Node() *discover.Node
	NodeId() discover.NodeId
	Peers() []Peer
	AddPeer(node *discover.Node)
	RemovePeer(node discover.NodeId)
	Bind(p Protocol)
	Start() error
	Stop()
}

func NewServer

func NewServer(config Config) Server

NewServer Creates background service object

Directories

Path Synopsis
rsa
examples
storage

Jump to

Keyboard shortcuts

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