Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple to use but full configurable p2p framework

License

NotificationsYou must be signed in to change notification settings

v-braun/go2p

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang p2p framework

Byv-braun - viktor-braun.de.

Build StatuscodecovGo Report CardDocumentationPR welcome

Description

GO2P is a P2P framework, designed with flexibility and simplicity in mind.You can use a pre configured stack (encryption, compression, etc.) or built your own based on the existing modules.

GO2P use themiddleware pattern as a core pattern for messages.If you have used expressJS, OWIN or other HTTP/Web based frameworks you should be familiar with that.
The basic idea is that an outgoing message is passed through multiple middleware functions. Each of this functions can manipulate the message.
A middleware function could encrypt, compress, log or sign the message.
Outgoing messages will be processed through the middleware functions and incomming messages in the inverted order:

Installation

go get github.com/v-braun/go2p

Usage

You like code? Checkout thechat example

The simplest way to use this framework is to create a new instance of the full configured TCP based network stack:

localAddr:="localhost:7077"net:=go2p.NewNetworkConnectionTCP(*localAddr,&map[string]func(peer*go2p.Peer,msg*go2p.Message){"msg":func(peer*go2p.Peer,msg*go2p.Message) {fmt.Printf("%s > %s\n",peer.RemoteAddress(),msg.PayloadGetString())},    })net.OnPeer(func(p*go2p.Peer) {fmt.Printf("new peer: %s\n",p.RemoteAddress())    })err:=net.Start()iferr!=nil {panic(err)    }defernet.Stop()// connects to another peer via tcpnet.ConnectTo("tcp","localhost:7077")// send a message to the 'msg' routenet.SendBroadcast(go2p.NewMessageRoutedFromString("msg","hello go2p"))

Advanced Usage

The function NewNetworkConnectionTCP is a shorthand for the advanced configuration of a network stack.

op:=go2p.NewTCPOperator("tcp",localAddr)// creates a tcp based operator (net.Dialer and net.Listener)peerStore:=go2p.NewDefaultPeerStore(10)// creates a simple peer store that limits connections to 10conn:=go2p.NewNetworkConnection().// creates a new instance of the builderWithOperator(op).// adds the operator to the network stackWithPeerStore(peerStore).// adds the peer store to the network stackWithMiddleware(go2p.Routes(routes)).// adds the routes middlewareWithMiddleware(go2p.Headers()).// adds the headers middlewareWithMiddleware(go2p.Crypt()).// adds encryptionWithMiddleware(go2p.Log()).// adds loggingBuild()// creates the network

This code creates a new NetworkConnection that use tcp communication, a default PeerStore and some middlewares.
Outgoing messages will now pass the following middlewares:

(app logic) -> Routing -> Headers -> Crypt -> Log -> (network)

Incomming messages will pass the following middlewares

(app logic) <- Routing <- Headers <- Crypt <- Log <- (network)

Authors

image
v-braun

Contributing

Make sure to read these guides before getting started:

License

go2p is available under the MIT License. SeeLICENSE for details.

About

Simple to use but full configurable p2p framework

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp