Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Project516/p2p-chat/llms.txt

Use this file to discover all available pages before exploring further.

p2p-chat is controlled entirely from the terminal. You start and manage sessions through top-level subcommands passed to go run ., and once a session is active you interact using slash commands typed directly into the chat prompt.

Top-level subcommands

These commands are passed as the first argument to go run . and control how p2p-chat establishes a connection.

listen <address>

Binds a TCP listener on the given address and waits for exactly one incoming connection. The process blocks until a peer connects.
go run . listen <address>
Parameters
ParameterRequiredDescription
addressYesThe host:port to listen on. Example: localhost:5555, 0.0.0.0:9000.
Expected output
Listening on localhost:5555
Once a peer connects:
Connected
Error casesIf you omit the address argument, p2p-chat prints an error and a default address message, then starts a listener on localhost:5555. However, the code immediately proceeds to read the missing args[2], which causes a runtime panic. Always pass the address explicitly.
Error: No port given
Defaulting to port :5555
panic: runtime error: index out of range [2] with length 2
The listener accepts exactly one connection. After that connection closes, the process exits. To start another session, run listen again.
Dials the host listening at the given address and establishes a TCP connection. After the connection succeeds, both sides perform a key exchange before the chat session begins.
go run . connect <address>
Parameters
ParameterRequiredDescription
addressYesThe host:port of the peer running listen. Example: localhost:5555.
Expected output
Connected to localhost:5555
Error casesIf the host is not reachable or no listener is running at the address, the Go runtime will print a dial error and the process exits.
Reads the version string from assets/version.txt at runtime and prints it to the terminal. This command does not start a connection.
go run . version
Expected output
p2p-chat version: 1.0.0
The version value reflects whatever is written in assets/version.txt at the time you run the command. The current version is 1.0.0.
Inside a live chat session, use the /version slash command instead — it reads the same file without exiting the program.
If you run go run . with no arguments, or with an unrecognized subcommand, p2p-chat prints a usage line and exits.
go run .
# Usage: go run . [listen|connect] address
No connection is attempted.

In-chat slash commands

Once a session is active (after listen accepts a connection or connect succeeds), you can type the following slash commands at the prompt. Commands prefixed with a / are intercepted locally before any text is sent to the peer.

/nick <nickname>

Changes your display name. All subsequent messages you send appear to the other peer as <nickname>> <text>. The name change is also broadcast to the peer as an alert.
/nick alice
Parameters
ParameterRequiredDescription
nicknameYesThe new display name. Must be non-empty.
What the peer seesIf your current nick is friend and you run /nick alice, the peer sees:
! friend changed their nickname to alice
The broadcast format is:
! <old_name> changed their nickname to <new_name>
Error cases
  • If you type /nick with no name (empty argument), p2p-chat prints an error locally and does not change the display name.
  • If the command string is too short to parse a name, the same local error is shown and nothing is sent to the peer.
The nickname change alert is sent over the encrypted connection. The peer sees it as a system message, not as a regular chat line.
Sends a leave notice to the peer and then exits the program. The peer receives a system message indicating you have left.
/quit
What the peer sees
!<nick> left the chat
No parameters. Anything typed after /quit is ignored.
Running /quit closes the connection immediately after sending the leave notice. There is no confirmation prompt.
Prints the help menu to your local terminal. Nothing is sent to the peer.
/help
The help output lists the available slash commands and their descriptions. It is printed only on your side of the connection.No parameters.
Reads assets/version.txt and prints the version string to your local terminal. Nothing is sent to the peer.
/version
Expected output
p2p version: 1.0.0
No parameters.
The in-chat /version command outputs p2p version: (without -chat), while the top-level go run . version subcommand outputs p2p-chat version:. Both read from the same assets/version.txt file.

Plain text messages

Any input that does not begin with / is treated as a chat message. The message is encrypted and sent to the peer, where it appears formatted as:
<nick>> <text>
Messages are encrypted before leaving your machine using NaCl box (XSalsa20-Poly1305). The peer decrypts them on receipt. See the encryption reference for details.
The maximum message size is 65,535 bytes — the largest value representable in the 2-byte uint16 length header used by the transport layer.

Shell script shortcuts

The repository includes three shell scripts that wrap common command-line invocations:
ScriptEquivalent command
host.shgo run . listen localhost:5555
connect.shgo run . connect localhost:5555
run.shgo fmt ./... && go vet ./... && go run .
bash host.sh       # start listener on localhost:5555
bash connect.sh    # connect to localhost:5555
bash run.sh        # format, vet, then run (no subcommand — prints usage)

Build docs developers (and LLMs) love