{"id":13756271,"url":"https://github.com/tendermint/go-p2p","last_synced_at":"2025-05-10T03:31:18.641Z","repository":{"id":57482088,"uuid":"44769997","full_name":"tendermint/go-p2p","owner":"tendermint","description":"DEPRECATED (moved to tendermint/tendermint): Golang P2P library","archived":true,"fork":false,"pushed_at":"2017-04-21T22:02:35.000Z","size":229,"stargazers_count":120,"open_issues_count":1,"forks_count":32,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-08-03T11:01:51.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tendermint.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-22T20:00:51.000Z","updated_at":"2023-09-26T07:25:34.000Z","dependencies_parsed_at":"2022-09-02T06:11:05.712Z","dependency_job_id":null,"html_url":"https://github.com/tendermint/go-p2p","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/tendermint%2Fgo-p2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tendermint%2Fgo-p2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tendermint%2Fgo-p2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tendermint%2Fgo-p2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tendermint","download_url":"https://codeload.github.com/tendermint/go-p2p/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224911421,"owners_count":17390840,"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":[],"created_at":"2024-08-03T11:00:40.410Z","updated_at":"2024-11-16T11:31:24.783Z","avatar_url":"https://github.com/tendermint.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# `tendermint/go-p2p`\n\n[![CircleCI](https://circleci.com/gh/tendermint/go-p2p.svg?style=svg)](https://circleci.com/gh/tendermint/go-p2p)\n\n`tendermint/go-p2p` provides an abstraction around peer-to-peer communication.\u003cbr/\u003e\n\n## Peer/MConnection/Channel\n\nEach peer has one `MConnection` (multiplex connection) instance.\n\n__multiplex__ *noun* a system or signal involving simultaneous transmission of\nseveral messages along a single channel of communication.\n\nEach `MConnection` handles message transmission on multiple abstract communication\n`Channel`s.  Each channel has a globally unique byte id.\nThe byte id and the relative priorities of each `Channel` are configured upon\ninitialization of the connection.\n\nThere are two methods for sending messages:\n```go\nfunc (m MConnection) Send(chID byte, msg interface{}) bool {}\nfunc (m MConnection) TrySend(chID byte, msg interface{}) bool {}\n```\n\n`Send(chID, msg)` is a blocking call that waits until `msg` is successfully queued\nfor the channel with the given id byte `chID`.  The message `msg` is serialized\nusing the `tendermint/wire` submodule's `WriteBinary()` reflection routine.\n\n`TrySend(chID, msg)` is a nonblocking call that returns false if the channel's\nqueue is full.\n\n`Send()` and `TrySend()` are also exposed for each `Peer`.\n\n## Switch/Reactor\n\nThe `Switch` handles peer connections and exposes an API to receive incoming messages\non `Reactors`.  Each `Reactor` is responsible for handling incoming messages of one\nor more `Channels`.  So while sending outgoing messages is typically performed on the peer,\nincoming messages are received on the reactor.\n\n```go\n// Declare a MyReactor reactor that handles messages on MyChannelID.\ntype MyReactor struct{}\n\nfunc (reactor MyReactor) GetChannels() []*ChannelDescriptor {\n    return []*ChannelDescriptor{ChannelDescriptor{ID:MyChannelID, Priority: 1}}\n}\n\nfunc (reactor MyReactor) Receive(chID byte, peer *Peer, msgBytes []byte) {\n    r, n, err := bytes.NewBuffer(msgBytes), new(int64), new(error)\n    msgString := ReadString(r, n, err)\n    fmt.Println(msgString)\n}\n\n// Other Reactor methods omitted for brevity\n...\n\nswitch := NewSwitch([]Reactor{MyReactor{}})\n\n...\n\n// Send a random message to all outbound connections\nfor _, peer := range switch.Peers().List() {\n    if peer.IsOutbound() {\n        peer.Send(MyChannelID, \"Here's a random message\")\n    }\n}\n```\n\n### PexReactor/AddrBook\n\nA `PEXReactor` reactor implementation is provided to automate peer discovery.\n\n```go\nbook := p2p.NewAddrBook(addrBookFilePath)\npexReactor := p2p.NewPEXReactor(book)\n...\nswitch := NewSwitch([]Reactor{pexReactor, myReactor, ...})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftendermint%2Fgo-p2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftendermint%2Fgo-p2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftendermint%2Fgo-p2p/lists"}