{"id":51595368,"url":"https://github.com/monkey-mode/p2p-fundamentals","last_synced_at":"2026-07-11T18:30:27.215Z","repository":{"id":355732480,"uuid":"1229349084","full_name":"monkey-mode/p2p-fundamentals","owner":"monkey-mode","description":"Go exercise for P2P fundamentals: TCP sockets, sending messages between two peers","archived":false,"fork":false,"pushed_at":"2026-05-05T01:01:26.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-05T03:08:34.469Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monkey-mode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-05T00:34:00.000Z","updated_at":"2026-05-05T01:01:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/monkey-mode/p2p-fundamentals","commit_stats":null,"previous_names":["monkey-mode/p2p-fundamentals"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/monkey-mode/p2p-fundamentals","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkey-mode%2Fp2p-fundamentals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkey-mode%2Fp2p-fundamentals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkey-mode%2Fp2p-fundamentals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkey-mode%2Fp2p-fundamentals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monkey-mode","download_url":"https://codeload.github.com/monkey-mode/p2p-fundamentals/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monkey-mode%2Fp2p-fundamentals/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35372639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2026-07-11T18:30:26.469Z","updated_at":"2026-07-11T18:30:27.202Z","avatar_url":"https://github.com/monkey-mode.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# p2p-fundamentals\n\nA hands-on Go exercise exploring P2P networking fundamentals: TCP sockets, bidirectional peers, and line-delimited messaging.\n\n## What it does\n\nEach process acts as both a server and a client simultaneously:\n\n- **Listens** on a TCP port for incoming peer connections (goroutine in background)\n- **Dials** a remote peer and enters an interactive chat session (foreground)\n\nMessages are newline-delimited and sent over raw TCP. Incoming messages are printed to stdout with the sender's address as a prefix.\n\n## Project structure\n\n```\n.\n├── main.go        # CLI entrypoint — parses flags, wires up the peer\n└── peer/\n    └── peer.go    # Peer type: Start (listener), ConnectAndChat (dialer)\n```\n\n## Usage\n\n### Run Peer A (listen only, no remote yet)\n\n```bash\ngo run . -listen :3000\n```\n\n### Run Peer B (listen + connect to A)\n\n```bash\ngo run . -listen :3001 -connect localhost:3000\n```\n\nPeer B connects to Peer A and enters interactive mode. Type a message and press Enter — it appears on Peer A's terminal prefixed with Peer B's address.\n\n### Flags\n\n| Flag | Default | Description |\n|------|---------|-------------|\n| `-listen` | `:3000` | Local address to accept incoming connections on |\n| `-connect` | *(empty)* | Remote peer address to dial; omit to wait for inbound connections |\n\n## How it works\n\n1. `peer.New(addr)` creates a `Peer` with the given listen address.\n2. `p.Start()` opens a TCP listener and spawns a goroutine per accepted connection that reads lines and prints them.\n3. `p.ConnectAndChat(addr)` dials the remote address, then reads stdin line-by-line, writing each line to the connection.\n4. `\\n` is the message delimiter — `fmt.Fprintln` writes it on send, `bufio.Scanner` splits on it on receive.\n\n## Requirements\n\n- Go 1.21+\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonkey-mode%2Fp2p-fundamentals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonkey-mode%2Fp2p-fundamentals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonkey-mode%2Fp2p-fundamentals/lists"}