GithubHelp home page GithubHelp logo

go-libp2p-gostream's Introduction

go-libp2p-gostream

Build Status codecov standard-readme compliant

Go "net" wrappers for libp2p

Package gostream allows to replace the standard net stack in Go with LibP2P streams.

Given a libp2p.Host, gostream provides Dial() and Listen() methods which return implementations of net.Conn and net.Listener.

Instead of the regular "host:port" addressing, gostream uses a Peer ID, and rather than a raw TCP connection, gostream will use libp2p's net.Stream. This means your connections will take advantage of libp2p's multi-routes, NAT transversal and stream multiplexing.

Table of Contents

Install

This package is a library that uses Go modules for depedency management.

Usage

Documentation can be read at Godoc. The important bits follow.

A simple communication between peers -one acting as server and the other as client- would work like:

go func() {
	listener, _ := Listen(srvHost, tag)
	defer listener.Close()
	servConn, _ := listener.Accept()
	defer servConn.Close()
	reader := bufio.NewReader(servConn)
	msg, _ := reader.ReadString('\n')
	fmt.Println(msg)
	servConn.Write([]byte("answer!\n"))
}()
clientConn, _ := Dial(context.Background(), clientHost, srvHost.ID(), tag)
clientConn.Write([]byte("question?\n"))
resp, _ := ioutil.ReadAll(clientConn)
fmt.Println(resp)

Note error handling above is ommited.

Contribute

PRs accepted.

License

MIT © Protocol Labs, Inc.

go-libp2p-gostream's People

Contributors

hsanjuan avatar stebalien avatar web3-bot avatar dependabot-preview[bot] avatar marten-seemann avatar kubuxu avatar lanzafame avatar astafrode avatar raulk avatar nisainan avatar zenground0 avatar dirkmc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.