# briar/socks-socket architecture

> Architecture diagram of the GitHub repository briar/socks-socket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/briar/socks-socket
- Repository: https://github.com/briar/socks-socket

## Overview

This is a small Java SOCKS5 socket-factory library. A caller obtains a socket from the factory and connects it to an unresolved host; the socket opens a connection to the configured proxy, negotiates SOCKS5 (optionally with username/password authentication), and requests the destination connection. IoUtils handles socket streams and complete reads, while ByteUtils encodes the port. The excerpts show these internal calls; no README or evidence of other runtime capabilities was provided.

Main entry points: [`lib/src/main/java/org/briarproject/socks/SocksSocket.java`](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocket.java) (SOCKS5 socket), [`lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java`](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java) (SOCKS socket factory), [`lib/src/main/java/org/briarproject/util/IoUtils.java`](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/IoUtils.java) (Socket I/O helpers), [`lib/src/main/java/org/briarproject/util/ByteUtils.java`](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/ByteUtils.java) (Unsigned port encoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_socks["SOCKS connections"]
  node_factory["SOCKS socket factory"]
  node_socket["SOCKS5 socket<br/>[SocksSocket.java]"]
end

subgraph group_utilities["Encoding and I/O"]
  node_io["Socket I/O helpers<br/>[IoUtils.java]"]
  node_bytes["Unsigned port encoding<br/>[ByteUtils.java]"]
end

node_caller(("Socket consumer"))
node_proxy(("SOCKS proxy"))

node_caller -->|"requests socket"| node_factory
node_factory -->|"creates"| node_socket
node_caller -->|"connects to host"| node_socket
node_socket -->|"negotiates connection"| node_proxy
node_socket -->|"reads and writes"| node_io
node_socket -->|"encodes port"| node_bytes

click node_factory "https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java"
click node_socket "https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocket.java"
click node_io "https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/IoUtils.java"
click node_bytes "https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/ByteUtils.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_factory,node_socket toneBlue
class node_io,node_bytes toneAmber
class node_caller,node_proxy toneIndigo
```

## Components

### SOCKS connections

- [SOCKS socket factory](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java): `lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java`
- [SOCKS5 socket](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/socks/SocksSocket.java): `lib/src/main/java/org/briarproject/socks/SocksSocket.java`

### Encoding and I/O

- [Socket I/O helpers](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/IoUtils.java): `lib/src/main/java/org/briarproject/util/IoUtils.java`
- [Unsigned port encoding](https://github.com/briar/socks-socket/blob/master/lib/src/main/java/org/briarproject/util/ByteUtils.java): `lib/src/main/java/org/briarproject/util/ByteUtils.java`

### Other components

- **Socket consumer**
- **SOCKS proxy**

## Connections

- Socket consumer → SOCKS socket factory: requests socket (evidence: `lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java`)
- SOCKS socket factory → SOCKS5 socket: creates (evidence: `lib/src/main/java/org/briarproject/socks/SocksSocketFactory.java`)
- Socket consumer → SOCKS5 socket: connects to host
- SOCKS5 socket → SOCKS proxy: negotiates connection (evidence: `lib/src/main/java/org/briarproject/socks/SocksSocket.java`)
- SOCKS5 socket → Socket I/O helpers: reads and writes (evidence: `lib/src/main/java/org/briarproject/socks/SocksSocket.java`)
- SOCKS5 socket → Unsigned port encoding: encodes port (evidence: `lib/src/main/java/org/briarproject/socks/SocksSocket.java`)
