docs(handler/serial): add comprehensive English comments to all files
Add package-level architecture documentation describing two modes (hop-based forwarding and direct proxy), two-tier dialing strategy in forwardSerial, recorderConn per-packet logging with direction convention, and metadata parsing details. No code changes.
This commit is contained in:
@@ -10,11 +10,28 @@ import (
|
||||
"github.com/go-gost/core/recorder"
|
||||
)
|
||||
|
||||
// recorderConn wraps a net.Conn to record raw traffic flowing through it.
|
||||
// Each successful Read or Write that transfers data is logged via the
|
||||
// configured Recorder, optionally annotated with direction markers,
|
||||
// timestamps, and hex dumps.
|
||||
//
|
||||
// The direction convention is:
|
||||
// - Read: '>' (data entering GOST from the serial port / client side)
|
||||
// - Write: '<' (data leaving GOST toward the serial port / client side)
|
||||
//
|
||||
// This provides a per-packet-level traffic log, as opposed to the
|
||||
// aggregate stats approach used by handlers like redirect/tcp (which
|
||||
// accumulate total byte counts and record once at the end).
|
||||
type recorderConn struct {
|
||||
net.Conn
|
||||
recorder recorder.RecorderObject
|
||||
}
|
||||
|
||||
// Read reads from the underlying connection and records the received data.
|
||||
// Recording happens only when bytes were actually read (n > 0) AND a
|
||||
// Recorder is configured. If Read returns an error alongside data
|
||||
// (e.g. io.EOF after the last chunk), the data is still recorded —
|
||||
// partial reads before an error are meaningful traffic.
|
||||
func (c *recorderConn) Read(b []byte) (n int, err error) {
|
||||
n, err = c.Conn.Read(b)
|
||||
|
||||
@@ -40,6 +57,10 @@ func (c *recorderConn) Read(b []byte) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Write writes to the underlying connection and records the sent data.
|
||||
// Recording follows the same rules as Read: only when n > 0 and a
|
||||
// Recorder is configured. The direction marker is '<' to indicate
|
||||
// outbound traffic (data leaving GOST toward the target).
|
||||
func (c *recorderConn) Write(b []byte) (n int, err error) {
|
||||
n, err = c.Conn.Write(b)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user