{"id":20439849,"url":"https://github.com/v-braun/go2p","last_synced_at":"2025-04-12T22:43:13.059Z","repository":{"id":96755323,"uuid":"194547961","full_name":"v-braun/go2p","owner":"v-braun","description":"Simple to use but full configurable p2p framework","archived":false,"fork":false,"pushed_at":"2024-01-17T04:57:41.000Z","size":44148,"stargazers_count":94,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T22:42:43.287Z","etag":null,"topics":["distributed-systems","golang","network","network-stack","p2p","p2p-network","peer-to-peer"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/v-braun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-30T18:25:19.000Z","updated_at":"2025-01-02T02:24:12.000Z","dependencies_parsed_at":"2023-03-22T21:41:32.317Z","dependency_job_id":null,"html_url":"https://github.com/v-braun/go2p","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v-braun%2Fgo2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v-braun%2Fgo2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v-braun%2Fgo2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v-braun%2Fgo2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/v-braun","download_url":"https://codeload.github.com/v-braun/go2p/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643046,"owners_count":21138353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","golang","network","network-stack","p2p","p2p-network","peer-to-peer"],"created_at":"2024-11-15T09:19:55.834Z","updated_at":"2025-04-12T22:43:13.026Z","avatar_url":"https://github.com/v-braun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go2p\r\n\u003e golang p2p framework\r\n\r\nBy [v-braun - viktor-braun.de](https://viktor-braun.de).\r\n\r\n[![Build Status](https://img.shields.io/travis/v-braun/go2p.svg?style=flat-square)](https://travis-ci.org/v-braun/go2p)\r\n[![codecov](https://codecov.io/gh/v-braun/go2p/branch/master/graph/badge.svg)](https://codecov.io/gh/v-braun/go2p)\r\n[![Go Report Card](https://goreportcard.com/badge/github.com/v-braun/go2p)](https://goreportcard.com/report/github.com/v-braun/go2p)\r\n[![Documentation](https://godoc.org/github.com/v-braun/go2p?status.svg)](http://godoc.org/github.com/v-braun/go2p)\r\n![PR welcome](https://img.shields.io/badge/PR-welcome-green.svg?style=flat-square)\r\n[![](https://img.shields.io/github/license/v-braun/go2p.svg?style=flat-square)](https://github.com/v-braun/go2p/blob/master/LICENSE)\r\n\r\n\r\n\r\n\u003cp align=\"center\"\u003e\r\n\u003cimg width=\"70%\" src=\"./idea/logo-1.svg\" /\u003e\r\n\u003c/p\u003e\r\n\r\n\r\n## Description\r\n\r\nGO2P is a P2P framework, designed with flexibility and simplicity in mind. \r\nYou can use a pre configured stack (encryption, compression, etc.) or built your own based on the existing modules. \r\n\r\nGO2P use the [middleware pattern](https://dzone.com/articles/understanding-middleware-pattern-in-expressjs) as a core pattern for messages. \r\nIf you have used expressJS, OWIN or other HTTP/Web based frameworks you should be familiar with that.   \r\nThe basic idea is that an outgoing message is passed through multiple middleware functions. Each of this functions can manipulate the message.  \r\nA middleware function could encrypt, compress, log or sign the message.  \r\nOutgoing messages will be processed through the middleware functions and incomming messages in the inverted order:  \r\n\r\n\u003cp align=\"center\"\u003e\r\n\u003cimg width=\"70%\" src=\"./idea/middleware-overview.svg\" /\u003e\r\n\u003c/p\u003e\r\n\r\n\r\n\r\n\r\n## Installation\r\n```sh\r\ngo get github.com/v-braun/go2p\r\n```\r\n\r\n\r\n\r\n## Usage\r\n\r\n\u003e You like code? Checkout the [chat example](https://github.com/v-braun/go2p/blob/master/example_test.go)\r\n\r\nThe simplest way to use this framework is to create a new instance of the full configured TCP based network stack:\r\n\r\n``` go\r\n    localAddr := \"localhost:7077\"\r\n\tnet := go2p.NewNetworkConnectionTCP(*localAddr, \u0026map[string]func(peer *go2p.Peer, msg *go2p.Message){\r\n\t\t\"msg\": func(peer *go2p.Peer, msg *go2p.Message) {\r\n\t\t\tfmt.Printf(\"%s \u003e %s\\n\", peer.RemoteAddress(), msg.PayloadGetString())\r\n\t\t},\r\n    })\r\n    \r\n    net.OnPeer(func(p *go2p.Peer) {\r\n\t\tfmt.Printf(\"new peer: %s\\n\", p.RemoteAddress())\r\n    })\r\n    \r\n    err := net.Start()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n    }\r\n\r\n    defer net.Stop()\r\n    \r\n\r\n    // connects to another peer via tcp\r\n    net.ConnectTo(\"tcp\", \"localhost:7077\")\r\n\r\n    // send a message to the 'msg' route \r\n    net.SendBroadcast(go2p.NewMessageRoutedFromString(\"msg\", \"hello go2p\"))\r\n\r\n\r\n\r\n```\r\n\r\n## Advanced Usage\r\n\r\nThe function NewNetworkConnectionTCP is a shorthand for the advanced configuration of a network stack. \r\n\r\n``` go\r\n\top := go2p.NewTCPOperator(\"tcp\", localAddr) // creates a tcp based operator (net.Dialer and net.Listener)\r\n\tpeerStore := go2p.NewDefaultPeerStore(10) // creates a simple peer store that limits connections to 10\r\n\r\n\tconn := go2p.NewNetworkConnection(). // creates a new instance of the builder\r\n\t\tWithOperator(op). // adds the operator to the network stack\r\n\t\tWithPeerStore(peerStore). // adds the peer store to the network stack\r\n\t\tWithMiddleware(go2p.Routes(routes)). // adds the routes middleware\r\n\t\tWithMiddleware(go2p.Headers()). // adds the headers middleware\r\n\t\tWithMiddleware(go2p.Crypt()). // adds encryption\r\n\t\tWithMiddleware(go2p.Log()). // adds logging\r\n\t\tBuild() // creates the network \r\n```\r\n\r\nThis code creates a new NetworkConnection that use tcp communication, a default PeerStore and some middlewares.  \r\nOutgoing messages will now pass the following middlewares:  \r\n``` \r\n(app logic) -\u003e Routing -\u003e Headers -\u003e Crypt -\u003e Log -\u003e (network) \r\n``` \r\n\r\nIncomming messages will pass the following middlewares  \r\n``` \r\n(app logic) \u003c- Routing \u003c- Headers \u003c- Crypt \u003c- Log \u003c- (network)\r\n``` \r\n\r\n\r\n\r\n\r\n\r\n## Authors\r\n\r\n![image](https://avatars3.githubusercontent.com/u/4738210?v=3\u0026amp;s=50)  \r\n[v-braun](https://github.com/v-braun/)\r\n\r\n\r\n\r\n## Contributing\r\n\r\nMake sure to read these guides before getting started:\r\n- [Contribution Guidelines](https://github.com/v-braun/go2p/blob/master/CONTRIBUTING.md)\r\n- [Code of Conduct](https://github.com/v-braun/go2p/blob/master/CODE_OF_CONDUCT.md)\r\n\r\n## License\r\n**go2p** is available under the MIT License. See [LICENSE](https://github.com/v-braun/go2p/blob/master/LICENSE) for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv-braun%2Fgo2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fv-braun%2Fgo2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv-braun%2Fgo2p/lists"}