{"id":46484871,"url":"https://github.com/leprosus/golang-p2p","last_synced_at":"2026-03-06T09:12:09.188Z","repository":{"id":45553849,"uuid":"346109162","full_name":"leprosus/golang-p2p","owner":"leprosus","description":"Golang TCP simple client and server","archived":false,"fork":false,"pushed_at":"2023-05-03T05:40:34.000Z","size":96,"stargazers_count":48,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-19T01:56:18.063Z","etag":null,"topics":["golang","tcp","tcp-client","tcp-server","tcp-socket"],"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/leprosus.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2021-03-09T18:45:11.000Z","updated_at":"2024-06-18T13:10:35.000Z","dependencies_parsed_at":"2024-06-19T01:32:20.468Z","dependency_job_id":"cfef0487-1cdf-4901-a986-141efec89004","html_url":"https://github.com/leprosus/golang-p2p","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/leprosus/golang-p2p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leprosus%2Fgolang-p2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leprosus%2Fgolang-p2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leprosus%2Fgolang-p2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leprosus%2Fgolang-p2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leprosus","download_url":"https://codeload.github.com/leprosus/golang-p2p/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leprosus%2Fgolang-p2p/sbom","scorecard":{"id":585449,"data":{"date":"2025-08-18","repo":{"name":"github.com/leprosus/golang-p2p","commit":"d02f22b2c152c840436a39f6422d6463b783d988"},"scorecard":{"version":"v5.2.1-41-g40576783","commit":"40576783fda6698350fcbbeaea760ff827433034"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T20:22:47.279Z","repository_id":45553849,"created_at":"2025-08-20T20:22:47.279Z","updated_at":"2025-08-20T20:22:47.279Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30168646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","tcp","tcp-client","tcp-server","tcp-socket"],"created_at":"2026-03-06T09:12:08.475Z","updated_at":"2026-03-06T09:12:09.175Z","avatar_url":"https://github.com/leprosus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang simple TCP client and server\n\nGolang-p2p is a small client and server to make p2p communication over TCP with RSA encryption.\n\nMain aim the package is to create an easy way of microservices communication.\n\n## Features\n\n| Feature                     | Description                                                                                                                                 |\n|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|\n| Gob, Json and Bytes support | You can send you structure or data in binary presentation or binary serialized                                                              |\n| RSA  handshake              | Every communication between a client and a server starts with RSA public keys handshake.\u003cbr/\u003eAll sending data are encrypted before sending. |\n\n## Import\n\n```go\nimport \"github.com/leprosus/golang-p2p\"\n```\n\n## Server example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\tp2p \"github.com/leprosus/golang-p2p\"\n)\n\ntype Hello struct {\n\tText string\n}\n\ntype Buy struct {\n\tText string\n}\n\nfunc main() {\n\ttcp := p2p.NewTCP(\"localhost\", \"8080\")\n\n\tserver, err := p2p.NewServer(tcp)\n\tif err != nil {\n\t\tlog.Panicln(err)\n\t}\n\n\tserver.SetHandler(\"dialog\", func(ctx context.Context, req p2p.Data) (res p2p.Data, err error) {\n\t\thello := Hello{}\n\t\terr = req.GetGob(\u0026hello)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\n\t\tfmt.Printf(\"\u003e Hello: %s\\n\", hello.Text)\n\n\t\tres = p2p.Data{}\n\t\terr = res.SetGob(Buy{\n\t\t\tText: hello.Text,\n\t\t})\n\n\t\treturn\n\t})\n\n\terr = server.Serve()\n\tif err != nil {\n\t\tlog.Panicln(err)\n\t}\n}\n```\n\n## Client example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\tp2p \"github.com/leprosus/golang-p2p\"\n)\n\ntype Hello struct {\n\tText string\n}\n\ntype Buy struct {\n\tText string\n}\n\nfunc main() {\n\ttcp := p2p.NewTCP(\"localhost\", \"8080\")\n\n\tclient, err := p2p.NewClient(tcp)\n\tif err != nil {\n\t\tlog.Panicln(err)\n\t}\n\n\tvar req, res p2p.Data\n\n\tfor i := 0; i \u003c 10; i++ {\n\t\treq = p2p.Data{}\n\t\terr = req.SetGob(Hello{\n\t\t\tText: fmt.Sprintf(\"User #%d\", i+1),\n\t\t})\n\t\tif err != nil {\n\t\t\tlog.Panicln(err)\n\t\t}\n\n\t\tres = p2p.Data{}\n\t\tres, err = client.Send(\"dialog\", req)\n\t\tif err != nil {\n\t\t\tlog.Panicln(err)\n\t\t}\n\n\t\tvar buy Buy\n\t\terr = res.GetGob(\u0026buy)\n\t\tif err != nil {\n\t\t\tlog.Panicln(err)\n\t\t}\n\n\t\tfmt.Printf(\"\u003e Buy: %s\\n\", buy.Text)\n\t}\n}\n```\n\n## Running\n\nIf you run the server and the client separately then you see:\n\n* in the server stdout:\n\n```text\n\u003e Hello: User #1\ndialog: addr (127.0.0.1:50099), handshake (2 ms), read (7 ms), handle (278 µs), write (301 µs), total (10 ms)\n\u003e Hello: User #2\ndialog: addr (127.0.0.1:50100), read (743 µs), handle (238 µs), write (219 µs), total (1 ms)\n\u003e Hello: User #3\ndialog: addr (127.0.0.1:50101), read (834 µs), handle (233 µs), write (228 µs), total (1 ms)\n\u003e Hello: User #4\ndialog: addr (127.0.0.1:50102), read (547 µs), handle (227 µs), write (260 µs), total (1 ms)\n\u003e Hello: User #5\ndialog: addr (127.0.0.1:50103), read (625 µs), handle (230 µs), write (271 µs), total (1 ms)\n\u003e Hello: User #6\ndialog: addr (127.0.0.1:50104), read (602 µs), handle (241 µs), write (234 µs), total (1 ms)\n\u003e Hello: User #7\ndialog: addr (127.0.0.1:50105), read (589 µs), handle (258 µs), write (227 µs), total (1 ms)\n\u003e Hello: User #8\ndialog: addr (127.0.0.1:50106), read (635 µs), handle (232 µs), write (221 µs), total (1 ms)\n\u003e Hello: User #9\ndialog: addr (127.0.0.1:50107), read (1 ms), handle (376 µs), write (365 µs), total (1 ms)\n\u003e Hello: User #10\ndialog: addr (127.0.0.1:50108), read (635 µs), handle (370 µs), write (434 µs), total (1 ms)\n\n```\n\n* in the client stdout:\n\n```text\ndialog: addr (127.0.0.1:8080), handshake (8 ms), write (480 µs), read (1 ms), total (10 ms)\n\u003e Buy: User #1\ndialog: addr (127.0.0.1:8080), write (342 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #2\ndialog: addr (127.0.0.1:8080), write (451 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #3\ndialog: addr (127.0.0.1:8080), write (226 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #4\ndialog: addr (127.0.0.1:8080), write (246 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #5\ndialog: addr (127.0.0.1:8080), write (262 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #6\ndialog: addr (127.0.0.1:8080), write (262 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #7\ndialog: addr (127.0.0.1:8080), write (247 µs), read (1 ms), total (1 ms)\n\u003e Buy: User #8\ndialog: addr (127.0.0.1:8080), write (599 µs), read (2 ms), total (2 ms)\n\u003e Buy: User #9\ndialog: addr (127.0.0.1:8080), write (259 µs), read (2 ms), total (2 ms)\n\u003e Buy: User #10\n```\n\n* logging\n\nAll lines that start from `dialog` is the topic for the communication.\n\nAll log lines write to StdOut.\n\nIf you want to reassign this logger you need to implement your own with the following interface:\n\n```go\ntype Logger interface {\n    Info(msg string)\n    Warn(msg string)\n    Error(msg string)\n}\n```\n\nand set it up in your server or client implementation this way:\n\n```go\nsettings.SetLogger(yourLogger)\n```\n\n## List all methods\n\n### TCP Initialization\n\n* p2p.NewTCP(host, port) (tcp, err) - creates TCP connection\n\n### Server settings initialization\n\n* p2p.NewServerSettings() (settings) - creates a new server's settings\n* settings.SetConnTimeout(duration) - sets connection timout\n* settings.SetHandleTimeout(duration) - sets handle timout\n* settings.SetBodyLimit(limit) - sets max body size for reading\n\n### Server\n\n* p2p.NewServer(tcp) (server, error) - creates a new server\n* server.SetSettings(settings) - sets server settings\n* server.SetLogger(logger) - reassigns server's logger\n* server.SetHandler(topic, handler) - sets a handler that processes all request with defined topic\n* server.SetContext(context) - sets context\n* server.GetContext() (context) - returns context\n* server.Serve() (error) - starts to serve\n\n### Client settings initialization\n\n* p2p.NewClientSettings() (settings) - creates a new server's settings\n* settings.SetConnTimeout(duration) - sets connection timout\n* settings.SetBodyLimit(limit) - sets max body size for writing\n* settings.SetRetry(retries, delay) - sets retry parameters\n\n### Client\n\n* NewClient(tcp, settings) (client, error) - creates a new client\n* client.SetSettings(settings) - sets client settings\n* client.SetLogger(logger) - reassigns client's logger\n* client.Send(topic, request) (response, error) - sends a request to a server by the topic\n\n### Request and Response\n\n* data.SetBytes(bytes) - sets bytes to the request/response\n* data.GetBytes() (bytes) - gets bytes from the request/response\n* data.SetGob(obj) (error) - encodes to Gob and sets structure to the request/response\n* data.GetGob(obj) (error) - decode from Gob and gets structure from the request/response\n* data.SetJson(obj) (error) - encodes to JSON and sets structure to the request/response\n* data.GetJson(obj) (error) - decode from JSON and gets structure from the request/response\n* data.String() (string) - returns string from the request/response","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleprosus%2Fgolang-p2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleprosus%2Fgolang-p2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleprosus%2Fgolang-p2p/lists"}