This commit is contained in:
eyedeekay
2025-05-29 19:44:45 -04:00
parent 5899247685
commit a53acecb87
9 changed files with 3154 additions and 5 deletions

2
.gitignore vendored
View File

@ -2,4 +2,4 @@ review.md
SAMv3.md
testplan.md
err
/*.log
/*.log

1251
DOC.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,12 @@ test:
#make raw-test
#make primary-test
test-logs:
make common-test 2> common-err.log 1> common-out.log; cat common-err.log common-out.log
make stream-test 2> stream-err.log 1> stream-out.log; cat stream-err.log stream-out.log
make datagram-test 2> datagram-err.log 1> datagram-out.log; cat datagram-err.log datagram-out.log
#make raw-test 2> raw-err.log 1> raw-out.log; cat raw-err.log raw-out.log
#make primary-test 2> primary-err.log 1> primary-out.log; cat primary-err.log primary-out.log
godoc:
find ./*/ -type d -exec godocdown --output={}/DOC.md {} \;

View File

@ -5,9 +5,9 @@
A pure-Go implementation of SAMv3.3 (Simple Anonymous Messaging) for I2P, focused on maintainability and clean architecture. This project is forked from `github.com/go-i2p/sam3` with reorganized code structure.
**WARNING: This is a new package and nothing works yet.**
**BUT, the point of it is to have carefully designed fixes to sam3's rough edges, so the API should be stable**
**It should be ready soon but right now it's broke.**
**WARNING: This is a new package. Streaming works and so does some of datagrams.**
**The API should not change much.**
**It needs more people looking at it.**
## 📦 Installation

944
common/DOC.md Normal file
View File

@ -0,0 +1,944 @@
# common
--
import "github.com/go-i2p/go-sam-go/common"
## Usage
```go
const (
DEFAULT_SAM_MIN = "3.1"
DEFAULT_SAM_MAX = "3.3"
)
```
```go
const (
SESSION_OK = "SESSION STATUS RESULT=OK DESTINATION="
SESSION_DUPLICATE_ID = "SESSION STATUS RESULT=DUPLICATED_ID\n"
SESSION_DUPLICATE_DEST = "SESSION STATUS RESULT=DUPLICATED_DEST\n"
SESSION_INVALID_KEY = "SESSION STATUS RESULT=INVALID_KEY\n"
SESSION_I2P_ERROR = "SESSION STATUS RESULT=I2P_ERROR MESSAGE="
)
```
```go
const (
SIG_NONE = "SIGNATURE_TYPE=EdDSA_SHA512_Ed25519"
SIG_DSA_SHA1 = "SIGNATURE_TYPE=DSA_SHA1"
SIG_ECDSA_SHA256_P256 = "SIGNATURE_TYPE=ECDSA_SHA256_P256"
SIG_ECDSA_SHA384_P384 = "SIGNATURE_TYPE=ECDSA_SHA384_P384"
SIG_ECDSA_SHA512_P521 = "SIGNATURE_TYPE=ECDSA_SHA512_P521"
SIG_EdDSA_SHA512_Ed25519 = "SIGNATURE_TYPE=EdDSA_SHA512_Ed25519"
// Add a default constant that points to the recommended secure signature type
SIG_DEFAULT = SIG_EdDSA_SHA512_Ed25519
)
```
```go
const (
SAM_RESULT_OK = "RESULT=OK"
SAM_RESULT_INVALID_KEY = "RESULT=INVALID_KEY"
SAM_RESULT_KEY_NOT_FOUND = "RESULT=KEY_NOT_FOUND"
)
```
```go
const (
HELLO_REPLY_OK = "HELLO REPLY RESULT=OK"
HELLO_REPLY_NOVERSION = "HELLO REPLY RESULT=NOVERSION\n"
)
```
```go
const (
SESSION_STYLE_STREAM = "STREAM"
SESSION_STYLE_DATAGRAM = "DATAGRAM"
SESSION_STYLE_RAW = "RAW"
)
```
```go
const (
ACCESS_TYPE_WHITELIST = "whitelist"
ACCESS_TYPE_BLACKLIST = "blacklist"
ACCESS_TYPE_NONE = "none"
)
```
#### func ExtractDest
```go
func ExtractDest(input string) string
```
#### func ExtractPairInt
```go
func ExtractPairInt(input, value string) int
```
#### func ExtractPairString
```go
func ExtractPairString(input, value string) string
```
#### func IgnorePortError
```go
func IgnorePortError(err error) error
```
#### func RandPort
```go
func RandPort() (portNumber string, err error)
```
#### func SetAccessList
```go
func SetAccessList(s []string) func(*SAMEmit) error
```
SetAccessList tells the system to treat the AccessList as a whitelist
#### func SetAccessListType
```go
func SetAccessListType(s string) func(*SAMEmit) error
```
SetAccessListType tells the system to treat the AccessList as a whitelist
#### func SetAllowZeroIn
```go
func SetAllowZeroIn(b bool) func(*SAMEmit) error
```
SetAllowZeroIn tells the tunnel to accept zero-hop peers
#### func SetAllowZeroOut
```go
func SetAllowZeroOut(b bool) func(*SAMEmit) error
```
SetAllowZeroOut tells the tunnel to accept zero-hop peers
#### func SetCloseIdle
```go
func SetCloseIdle(b bool) func(*SAMEmit) error
```
SetCloseIdle tells the connection to close it's tunnels during extended idle
time.
#### func SetCloseIdleTime
```go
func SetCloseIdleTime(u int) func(*SAMEmit) error
```
SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
#### func SetCloseIdleTimeMs
```go
func SetCloseIdleTimeMs(u int) func(*SAMEmit) error
```
SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels
in milliseconds
#### func SetCompress
```go
func SetCompress(b bool) func(*SAMEmit) error
```
SetCompress tells clients to use compression
#### func SetEncrypt
```go
func SetEncrypt(b bool) func(*SAMEmit) error
```
SetEncrypt tells the router to use an encrypted leaseset
#### func SetFastRecieve
```go
func SetFastRecieve(b bool) func(*SAMEmit) error
```
SetFastRecieve tells clients to use compression
#### func SetInBackups
```go
func SetInBackups(u int) func(*SAMEmit) error
```
SetInBackups sets the inbound tunnel backups
#### func SetInLength
```go
func SetInLength(u int) func(*SAMEmit) error
```
SetInLength sets the number of hops inbound
#### func SetInQuantity
```go
func SetInQuantity(u int) func(*SAMEmit) error
```
SetInQuantity sets the inbound tunnel quantity
#### func SetInVariance
```go
func SetInVariance(i int) func(*SAMEmit) error
```
SetInVariance sets the variance of a number of hops inbound
#### func SetLeaseSetKey
```go
func SetLeaseSetKey(s string) func(*SAMEmit) error
```
SetLeaseSetKey sets the host of the SAMEmit's SAM bridge
#### func SetLeaseSetPrivateKey
```go
func SetLeaseSetPrivateKey(s string) func(*SAMEmit) error
```
SetLeaseSetPrivateKey sets the host of the SAMEmit's SAM bridge
#### func SetLeaseSetPrivateSigningKey
```go
func SetLeaseSetPrivateSigningKey(s string) func(*SAMEmit) error
```
SetLeaseSetPrivateSigningKey sets the host of the SAMEmit's SAM bridge
#### func SetMessageReliability
```go
func SetMessageReliability(s string) func(*SAMEmit) error
```
SetMessageReliability sets the host of the SAMEmit's SAM bridge
#### func SetName
```go
func SetName(s string) func(*SAMEmit) error
```
SetName sets the host of the SAMEmit's SAM bridge
#### func SetOutBackups
```go
func SetOutBackups(u int) func(*SAMEmit) error
```
SetOutBackups sets the inbound tunnel backups
#### func SetOutLength
```go
func SetOutLength(u int) func(*SAMEmit) error
```
SetOutLength sets the number of hops outbound
#### func SetOutQuantity
```go
func SetOutQuantity(u int) func(*SAMEmit) error
```
SetOutQuantity sets the outbound tunnel quantity
#### func SetOutVariance
```go
func SetOutVariance(i int) func(*SAMEmit) error
```
SetOutVariance sets the variance of a number of hops outbound
#### func SetReduceIdle
```go
func SetReduceIdle(b bool) func(*SAMEmit) error
```
SetReduceIdle tells the connection to reduce it's tunnels during extended idle
time.
#### func SetReduceIdleQuantity
```go
func SetReduceIdleQuantity(u int) func(*SAMEmit) error
```
SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle
time
#### func SetReduceIdleTime
```go
func SetReduceIdleTime(u int) func(*SAMEmit) error
```
SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
#### func SetReduceIdleTimeMs
```go
func SetReduceIdleTimeMs(u int) func(*SAMEmit) error
```
SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels
in milliseconds
#### func SetSAMAddress
```go
func SetSAMAddress(s string) func(*SAMEmit) error
```
SetSAMAddress sets the SAM address all-at-once
#### func SetSAMHost
```go
func SetSAMHost(s string) func(*SAMEmit) error
```
SetSAMHost sets the host of the SAMEmit's SAM bridge
#### func SetSAMPort
```go
func SetSAMPort(s string) func(*SAMEmit) error
```
SetSAMPort sets the port of the SAMEmit's SAM bridge using a string
#### func SetType
```go
func SetType(s string) func(*SAMEmit) error
```
SetType sets the type of the forwarder server
#### func SplitHostPort
```go
func SplitHostPort(hostport string) (string, string, error)
```
#### type BaseSession
```go
type BaseSession struct {
SAM SAM
}
```
#### func (*BaseSession) Close
```go
func (bs *BaseSession) Close() error
```
#### func (*BaseSession) From
```go
func (bs *BaseSession) From() string
```
#### func (*BaseSession) ID
```go
func (bs *BaseSession) ID() string
```
#### func (*BaseSession) Keys
```go
func (bs *BaseSession) Keys() i2pkeys.I2PKeys
```
#### func (*BaseSession) LocalAddr
```go
func (bs *BaseSession) LocalAddr() net.Addr
```
#### func (*BaseSession) Read
```go
func (bs *BaseSession) Read(b []byte) (int, error)
```
#### func (*BaseSession) RemoteAddr
```go
func (bs *BaseSession) RemoteAddr() net.Addr
```
#### func (*BaseSession) SetDeadline
```go
func (bs *BaseSession) SetDeadline(t time.Time) error
```
#### func (*BaseSession) SetReadDeadline
```go
func (bs *BaseSession) SetReadDeadline(t time.Time) error
```
#### func (*BaseSession) SetWriteDeadline
```go
func (bs *BaseSession) SetWriteDeadline(t time.Time) error
```
#### func (*BaseSession) To
```go
func (bs *BaseSession) To() string
```
#### func (*BaseSession) Write
```go
func (bs *BaseSession) Write(b []byte) (int, error)
```
#### type I2PConfig
```go
type I2PConfig struct {
SamHost string
SamPort int
TunName string
SamMin string
SamMax string
Fromport string
Toport string
Style string
TunType string
DestinationKeys *i2pkeys.I2PKeys
SigType string
EncryptLeaseSet bool
LeaseSetKey string
LeaseSetPrivateKey string
LeaseSetPrivateSigningKey string
LeaseSetKeys i2pkeys.I2PKeys
InAllowZeroHop bool
OutAllowZeroHop bool
InLength int
OutLength int
InQuantity int
OutQuantity int
InVariance int
OutVariance int
InBackupQuantity int
OutBackupQuantity int
FastRecieve bool
UseCompression bool
MessageReliability string
CloseIdle bool
CloseIdleTime int
ReduceIdle bool
ReduceIdleTime int
ReduceIdleQuantity int
LeaseSetEncryption string
// Streaming Library options
AccessListType string
AccessList []string
}
```
I2PConfig is a struct which manages I2P configuration options.
#### func NewConfig
```go
func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error)
```
#### func (*I2PConfig) Accesslist
```go
func (f *I2PConfig) Accesslist() string
```
Accesslist generates the I2CP access list configuration string based on the
configured access list
#### func (*I2PConfig) Accesslisttype
```go
func (f *I2PConfig) Accesslisttype() string
```
Accesslisttype returns the I2CP access list configuration string based on the
AccessListType setting
#### func (*I2PConfig) Close
```go
func (f *I2PConfig) Close() string
```
Close returns I2CP close-on-idle configuration settings as a string if enabled
#### func (*I2PConfig) DestinationKey
```go
func (f *I2PConfig) DestinationKey() string
```
DestinationKey returns the DESTINATION configuration string for the SAM bridge
If destination keys are set, returns them as a string, otherwise returns
"TRANSIENT"
#### func (*I2PConfig) DoZero
```go
func (f *I2PConfig) DoZero() string
```
DoZero returns the zero hop and fast receive configuration string settings
#### func (*I2PConfig) EncryptLease
```go
func (f *I2PConfig) EncryptLease() string
```
EncryptLease returns the lease set encryption configuration string Returns
"i2cp.encryptLeaseSet=true" if encryption is enabled, empty string otherwise
#### func (*I2PConfig) FromPort
```go
func (f *I2PConfig) FromPort() string
```
FromPort returns the FROM_PORT configuration string for SAM bridges >= 3.1
Returns an empty string if SAM version < 3.1 or if fromport is "0"
#### func (*I2PConfig) ID
```go
func (f *I2PConfig) ID() string
```
ID returns the tunnel name as a formatted string. If no tunnel name is set,
generates a random 12-character name using lowercase letters.
#### func (*I2PConfig) InboundBackupQuantity
```go
func (f *I2PConfig) InboundBackupQuantity() string
```
#### func (*I2PConfig) InboundLength
```go
func (f *I2PConfig) InboundLength() string
```
#### func (*I2PConfig) InboundLengthVariance
```go
func (f *I2PConfig) InboundLengthVariance() string
```
#### func (*I2PConfig) InboundQuantity
```go
func (f *I2PConfig) InboundQuantity() string
```
#### func (*I2PConfig) LeaseSetEncryptionType
```go
func (f *I2PConfig) LeaseSetEncryptionType() string
```
LeaseSetEncryptionType returns the I2CP lease set encryption type configuration
string. If no encryption type is set, returns default value "4,0". Validates
that all encryption types are valid integers.
#### func (*I2PConfig) LeaseSetSettings
```go
func (f *I2PConfig) LeaseSetSettings() (string, string, string)
```
Leasesetsettings returns the lease set configuration strings for I2P Returns
three strings: lease set key, private key, and private signing key settings
#### func (*I2PConfig) MaxSAM
```go
func (f *I2PConfig) MaxSAM() string
```
MaxSAM returns the maximum SAM version supported as a string If no maximum
version is set, returns default value "3.1"
#### func (*I2PConfig) MinSAM
```go
func (f *I2PConfig) MinSAM() string
```
MinSAM returns the minimum SAM version supported as a string If no minimum
version is set, returns default value "3.0"
#### func (*I2PConfig) OutboundBackupQuantity
```go
func (f *I2PConfig) OutboundBackupQuantity() string
```
#### func (*I2PConfig) OutboundLength
```go
func (f *I2PConfig) OutboundLength() string
```
#### func (*I2PConfig) OutboundLengthVariance
```go
func (f *I2PConfig) OutboundLengthVariance() string
```
#### func (*I2PConfig) OutboundQuantity
```go
func (f *I2PConfig) OutboundQuantity() string
```
#### func (*I2PConfig) Print
```go
func (f *I2PConfig) Print() []string
```
Print returns a slice of strings containing all the I2P configuration settings
#### func (*I2PConfig) Reduce
```go
func (f *I2PConfig) Reduce() string
```
Reduce returns I2CP reduce-on-idle configuration settings as a string if enabled
#### func (*I2PConfig) Reliability
```go
func (f *I2PConfig) Reliability() string
```
Reliability returns the message reliability configuration string for the SAM
bridge If a reliability setting is specified, returns formatted
i2cp.messageReliability setting
#### func (*I2PConfig) SAMAddress
```go
func (f *I2PConfig) SAMAddress() string
```
SAMAddress returns the SAM bridge address in the format "host:port" This is a
convenience method that uses the Sam() function to get the address. It is used
to provide a consistent interface for retrieving the SAM address.
#### func (*I2PConfig) Sam
```go
func (f *I2PConfig) Sam() string
```
Sam returns the SAM bridge address as a string in the format "host:port"
#### func (*I2PConfig) SessionStyle
```go
func (f *I2PConfig) SessionStyle() string
```
SessionStyle returns the SAM session style configuration string If no style is
set, defaults to "STREAM"
#### func (*I2PConfig) SetSAMAddress
```go
func (f *I2PConfig) SetSAMAddress(addr string)
```
SetSAMAddress sets the SAM bridge host and port from a combined address string.
If no address is provided, it sets default values for the host and port.
#### func (*I2PConfig) SignatureType
```go
func (f *I2PConfig) SignatureType() string
```
SignatureType returns the SIGNATURE_TYPE configuration string for SAM bridges >=
3.1 Returns empty string if SAM version < 3.1 or if no signature type is set
#### func (*I2PConfig) ToPort
```go
func (f *I2PConfig) ToPort() string
```
ToPort returns the TO_PORT configuration string for SAM bridges >= 3.1 Returns
an empty string if SAM version < 3.1 or if toport is "0"
#### func (*I2PConfig) UsingCompression
```go
func (f *I2PConfig) UsingCompression() string
```
#### type Option
```go
type Option func(*SAMEmit) error
```
Option is a SAMEmit Option
#### type Options
```go
type Options map[string]string
```
options map
#### func (Options) AsList
```go
func (opts Options) AsList() (ls []string)
```
obtain sam options as list of strings
#### type SAM
```go
type SAM struct {
SAMEmit
SAMResolver
net.Conn
// Timeout for SAM connections
Timeout time.Duration
// Context for control of lifecycle
Context context.Context
}
```
Used for controlling I2Ps SAMv3.
#### func NewSAM
```go
func NewSAM(address string) (*SAM, error)
```
NewSAM creates a new SAM instance by connecting to the specified address,
performing the hello handshake, and initializing the SAM resolver. It returns a
pointer to the SAM instance or an error if any step fails. This function
combines connection establishment and hello handshake into a single step,
eliminating the need for separate helper functions. It also initializes the SAM
resolver directly after the connection is established. The SAM instance is ready
to use for further operations like session creation or name resolution.
#### func (*SAM) Close
```go
func (sam *SAM) Close() error
```
close this sam session
#### func (*SAM) EnsureKeyfile
```go
func (sam *SAM) EnsureKeyfile(fname string) (keys i2pkeys.I2PKeys, err error)
```
if keyfile fname does not exist
#### func (*SAM) Keys
```go
func (sam *SAM) Keys() (k *i2pkeys.I2PKeys)
```
#### func (*SAM) Lookup
```go
func (sam *SAM) Lookup(name string) (i2pkeys.I2PAddr, error)
```
Performs a lookup, probably this order: 1) routers known addresses, cached
addresses, 3) by asking peers in the I2P network.
#### func (SAM) NewGenericSession
```go
func (sam SAM) NewGenericSession(style, id string, keys i2pkeys.I2PKeys, extras []string) (Session, error)
```
Creates a new session with the style of either "STREAM", "DATAGRAM" or "RAW",
for a new I2P tunnel with name id, using the cypher keys specified, with the
I2CP/streaminglib-options as specified. Extra arguments can be specified by
setting extra to something else than []string{}. This sam3 instance is now a
session
#### func (SAM) NewGenericSessionWithSignature
```go
func (sam SAM) NewGenericSessionWithSignature(style, id string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error)
```
#### func (SAM) NewGenericSessionWithSignatureAndPorts
```go
func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error)
```
Creates a new session with the style of either "STREAM", "DATAGRAM" or "RAW",
for a new I2P tunnel with name id, using the cypher keys specified, with the
I2CP/streaminglib-options as specified. Extra arguments can be specified by
setting extra to something else than []string{}. This sam3 instance is now a
session
#### func (*SAM) NewKeys
```go
func (sam *SAM) NewKeys(sigType ...string) (i2pkeys.I2PKeys, error)
```
Creates the I2P-equivalent of an IP address, that is unique and only the one who
has the private keys can send messages from. The public keys are the I2P
desination (the address) that anyone can send messages to.
#### func (*SAM) ReadKeys
```go
func (sam *SAM) ReadKeys(r io.Reader) (err error)
```
read public/private keys from an io.Reader
#### type SAMEmit
```go
type SAMEmit struct {
I2PConfig
}
```
#### func NewEmit
```go
func NewEmit(opts ...func(*SAMEmit) error) (*SAMEmit, error)
```
#### func (*SAMEmit) Accept
```go
func (e *SAMEmit) Accept() string
```
#### func (*SAMEmit) AcceptBytes
```go
func (e *SAMEmit) AcceptBytes() []byte
```
#### func (*SAMEmit) Connect
```go
func (e *SAMEmit) Connect(dest string) string
```
#### func (*SAMEmit) ConnectBytes
```go
func (e *SAMEmit) ConnectBytes(dest string) []byte
```
#### func (*SAMEmit) Create
```go
func (e *SAMEmit) Create() string
```
#### func (*SAMEmit) CreateBytes
```go
func (e *SAMEmit) CreateBytes() []byte
```
#### func (*SAMEmit) GenerateDestination
```go
func (e *SAMEmit) GenerateDestination() string
```
#### func (*SAMEmit) GenerateDestinationBytes
```go
func (e *SAMEmit) GenerateDestinationBytes() []byte
```
#### func (*SAMEmit) Hello
```go
func (e *SAMEmit) Hello() string
```
#### func (*SAMEmit) HelloBytes
```go
func (e *SAMEmit) HelloBytes() []byte
```
#### func (*SAMEmit) Lookup
```go
func (e *SAMEmit) Lookup(name string) string
```
#### func (*SAMEmit) LookupBytes
```go
func (e *SAMEmit) LookupBytes(name string) []byte
```
#### func (*SAMEmit) SamOptionsString
```go
func (e *SAMEmit) SamOptionsString() string
```
#### type SAMResolver
```go
type SAMResolver struct {
*SAM
}
```
#### func NewFullSAMResolver
```go
func NewFullSAMResolver(address string) (*SAMResolver, error)
```
#### func NewSAMResolver
```go
func NewSAMResolver(parent *SAM) (*SAMResolver, error)
```
#### func (*SAMResolver) Resolve
```go
func (sam *SAMResolver) Resolve(name string) (i2pkeys.I2PAddr, error)
```
Performs a lookup, probably this order: 1) routers known addresses, cached
addresses, 3) by asking peers in the I2P network.
#### type Session
```go
type Session interface {
net.Conn
ID() string
Keys() i2pkeys.I2PKeys
Close() error
}
```

353
datagram/DOC.md Normal file
View File

@ -0,0 +1,353 @@
# datagram
--
import "github.com/go-i2p/go-sam-go/datagram"
## Usage
#### type Datagram
```go
type Datagram struct {
Data []byte
Source i2pkeys.I2PAddr
Local i2pkeys.I2PAddr
}
```
Datagram represents an I2P datagram message
#### type DatagramAddr
```go
type DatagramAddr struct {
}
```
DatagramAddr implements net.Addr for I2P datagram addresses
#### func (*DatagramAddr) Network
```go
func (a *DatagramAddr) Network() string
```
Network returns the network type
#### func (*DatagramAddr) String
```go
func (a *DatagramAddr) String() string
```
String returns the string representation of the address
#### type DatagramConn
```go
type DatagramConn struct {
}
```
DatagramConn implements net.PacketConn for I2P datagrams
#### func (*DatagramConn) Close
```go
func (c *DatagramConn) Close() error
```
Close closes the datagram connection
#### func (*DatagramConn) LocalAddr
```go
func (c *DatagramConn) LocalAddr() net.Addr
```
LocalAddr returns the local address
#### func (*DatagramConn) Read
```go
func (c *DatagramConn) Read(b []byte) (n int, err error)
```
Read implements net.Conn by wrapping ReadFrom. It reads data into the provided
byte slice and returns the number of bytes read. When reading, it also updates
the remote address of the connection. Note: This is not a typical use case for
datagrams, as they are connectionless. However, for compatibility with net.Conn,
we implement it this way.
#### func (*DatagramConn) ReadFrom
```go
func (c *DatagramConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
```
ReadFrom reads a datagram from the connection
#### func (*DatagramConn) RemoteAddr
```go
func (c *DatagramConn) RemoteAddr() net.Addr
```
RemoteAddr returns the remote address of the connection. For datagram
connections, this returns nil as there is no single remote address.
#### func (*DatagramConn) SetDeadline
```go
func (c *DatagramConn) SetDeadline(t time.Time) error
```
SetDeadline sets the read and write deadlines
#### func (*DatagramConn) SetReadDeadline
```go
func (c *DatagramConn) SetReadDeadline(t time.Time) error
```
SetReadDeadline sets the deadline for future ReadFrom calls
#### func (*DatagramConn) SetWriteDeadline
```go
func (c *DatagramConn) SetWriteDeadline(t time.Time) error
```
SetWriteDeadline sets the deadline for future WriteTo calls
#### func (*DatagramConn) Write
```go
func (c *DatagramConn) Write(b []byte) (n int, err error)
```
Write implements net.Conn by wrapping WriteTo. It writes data to the remote
address and returns the number of bytes written. It uses the remote address set
by the last Read operation. If no remote address is set, it returns an error.
Note: This is not a typical use case for datagrams, as they are connectionless.
However, for compatibility with net.Conn, we implement it this way.
#### func (*DatagramConn) WriteTo
```go
func (c *DatagramConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
```
WriteTo writes a datagram to the specified address
#### type DatagramListener
```go
type DatagramListener struct {
}
```
DatagramListener implements net.DatagramListener for I2P datagram connections
#### func (*DatagramListener) Accept
```go
func (l *DatagramListener) Accept() (net.Conn, error)
```
Accept waits for and returns the next packet connection to the listener
#### func (*DatagramListener) Addr
```go
func (l *DatagramListener) Addr() net.Addr
```
Addr returns the listener's network address
#### func (*DatagramListener) Close
```go
func (l *DatagramListener) Close() error
```
Close closes the packet listener
#### type DatagramReader
```go
type DatagramReader struct {
}
```
DatagramReader handles incoming datagram reception
#### func (*DatagramReader) Close
```go
func (r *DatagramReader) Close() error
```
#### func (*DatagramReader) ReceiveDatagram
```go
func (r *DatagramReader) ReceiveDatagram() (*Datagram, error)
```
ReceiveDatagram receives a datagram from any source
#### type DatagramSession
```go
type DatagramSession struct {
*common.BaseSession
}
```
DatagramSession represents a datagram session that can send and receive
datagrams
#### func NewDatagramSession
```go
func NewDatagramSession(sam *common.SAM, id string, keys i2pkeys.I2PKeys, options []string) (*DatagramSession, error)
```
NewDatagramSession creates a new datagram session
#### func (*DatagramSession) Addr
```go
func (s *DatagramSession) Addr() i2pkeys.I2PAddr
```
Addr returns the I2P address of this session
#### func (*DatagramSession) Close
```go
func (s *DatagramSession) Close() error
```
Close closes the datagram session and all associated resources
#### func (*DatagramSession) Dial
```go
func (ds *DatagramSession) Dial(destination string) (net.PacketConn, error)
```
Dial establishes a datagram connection to the specified destination
#### func (*DatagramSession) DialContext
```go
func (ds *DatagramSession) DialContext(ctx context.Context, destination string) (net.PacketConn, error)
```
DialContext establishes a datagram connection with context support
#### func (*DatagramSession) DialI2P
```go
func (ds *DatagramSession) DialI2P(addr i2pkeys.I2PAddr) (net.PacketConn, error)
```
DialI2P establishes a datagram connection to an I2P address
#### func (*DatagramSession) DialI2PContext
```go
func (ds *DatagramSession) DialI2PContext(ctx context.Context, addr i2pkeys.I2PAddr) (net.PacketConn, error)
```
DialI2PContext establishes a datagram connection to an I2P address with context
support
#### func (*DatagramSession) DialI2PTimeout
```go
func (ds *DatagramSession) DialI2PTimeout(addr i2pkeys.I2PAddr, timeout time.Duration) (net.PacketConn, error)
```
DialI2PTimeout establishes a datagram connection to an I2P address with timeout
#### func (*DatagramSession) DialTimeout
```go
func (ds *DatagramSession) DialTimeout(destination string, timeout time.Duration) (net.PacketConn, error)
```
DialTimeout establishes a datagram connection with a timeout
#### func (*DatagramSession) Listen
```go
func (s *DatagramSession) Listen() (*DatagramListener, error)
```
#### func (*DatagramSession) NewReader
```go
func (s *DatagramSession) NewReader() *DatagramReader
```
NewReader creates a DatagramReader for receiving datagrams
#### func (*DatagramSession) NewWriter
```go
func (s *DatagramSession) NewWriter() *DatagramWriter
```
NewWriter creates a DatagramWriter for sending datagrams
#### func (*DatagramSession) PacketConn
```go
func (s *DatagramSession) PacketConn() net.PacketConn
```
PacketConn returns a net.PacketConn interface for this session
#### func (*DatagramSession) ReceiveDatagram
```go
func (s *DatagramSession) ReceiveDatagram() (*Datagram, error)
```
ReceiveDatagram receives a datagram from any source
#### func (*DatagramSession) SendDatagram
```go
func (s *DatagramSession) SendDatagram(data []byte, dest i2pkeys.I2PAddr) error
```
SendDatagram sends a datagram to the specified destination
#### type DatagramWriter
```go
type DatagramWriter struct {
}
```
DatagramWriter handles outgoing datagram transmission
#### func (*DatagramWriter) SendDatagram
```go
func (w *DatagramWriter) SendDatagram(data []byte, dest i2pkeys.I2PAddr) error
```
SendDatagram sends a datagram to the specified destination
#### func (*DatagramWriter) SetTimeout
```go
func (w *DatagramWriter) SetTimeout(timeout time.Duration) *DatagramWriter
```
SetTimeout sets the timeout for datagram operations
#### type SAM
```go
type SAM struct {
*common.SAM
}
```
SAM wraps common.SAM to provide datagram-specific functionality
#### func (*SAM) NewDatagramSession
```go
func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string) (*DatagramSession, error)
```
NewDatagramSession creates a new datagram session with the SAM bridge
#### func (*SAM) NewDatagramSessionWithPorts
```go
func (s *SAM) NewDatagramSessionWithPorts(id, fromPort, toPort string, keys i2pkeys.I2PKeys, options []string) (*DatagramSession, error)
```
NewDatagramSessionWithPorts creates a new datagram session with port
specifications
#### func (*SAM) NewDatagramSessionWithSignature
```go
func (s *SAM) NewDatagramSessionWithSignature(id string, keys i2pkeys.I2PKeys, options []string, sigType string) (*DatagramSession, error)
```
NewDatagramSessionWithSignature creates a new datagram session with custom
signature type

6
primary/DOC.md Normal file
View File

@ -0,0 +1,6 @@
# primary
--
import "github.com/go-i2p/go-sam-go/primary"
## Usage

341
raw/DOC.md Normal file
View File

@ -0,0 +1,341 @@
# raw
--
import "github.com/go-i2p/go-sam-go/raw"
## Usage
#### type RawAddr
```go
type RawAddr struct {
}
```
RawAddr implements net.Addr for I2P raw addresses
#### func (*RawAddr) Network
```go
func (a *RawAddr) Network() string
```
Network returns the network type
#### func (*RawAddr) String
```go
func (a *RawAddr) String() string
```
String returns the string representation of the address
#### type RawConn
```go
type RawConn struct {
}
```
RawConn implements net.PacketConn for I2P raw datagrams
#### func (*RawConn) Close
```go
func (c *RawConn) Close() error
```
Close closes the raw connection
#### func (*RawConn) LocalAddr
```go
func (c *RawConn) LocalAddr() net.Addr
```
LocalAddr returns the local address
#### func (*RawConn) Read
```go
func (c *RawConn) Read(b []byte) (n int, err error)
```
Read implements net.Conn by wrapping ReadFrom
#### func (*RawConn) ReadFrom
```go
func (c *RawConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
```
ReadFrom reads a raw datagram from the connection
#### func (*RawConn) RemoteAddr
```go
func (c *RawConn) RemoteAddr() net.Addr
```
RemoteAddr returns the remote address of the connection
#### func (*RawConn) SetDeadline
```go
func (c *RawConn) SetDeadline(t time.Time) error
```
SetDeadline sets the read and write deadlines
#### func (*RawConn) SetReadDeadline
```go
func (c *RawConn) SetReadDeadline(t time.Time) error
```
SetReadDeadline sets the deadline for future ReadFrom calls
#### func (*RawConn) SetWriteDeadline
```go
func (c *RawConn) SetWriteDeadline(t time.Time) error
```
SetWriteDeadline sets the deadline for future WriteTo calls
#### func (*RawConn) Write
```go
func (c *RawConn) Write(b []byte) (n int, err error)
```
Write implements net.Conn by wrapping WriteTo
#### func (*RawConn) WriteTo
```go
func (c *RawConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
```
WriteTo writes a raw datagram to the specified address
#### type RawDatagram
```go
type RawDatagram struct {
Data []byte
Source i2pkeys.I2PAddr
Local i2pkeys.I2PAddr
}
```
RawDatagram represents an I2P raw datagram message
#### type RawListener
```go
type RawListener struct {
}
```
RawListener implements net.Listener for I2P raw connections
#### func (*RawListener) Accept
```go
func (l *RawListener) Accept() (net.Conn, error)
```
Accept waits for and returns the next raw connection to the listener
#### func (*RawListener) Addr
```go
func (l *RawListener) Addr() net.Addr
```
Addr returns the listener's network address
#### func (*RawListener) Close
```go
func (l *RawListener) Close() error
```
Close closes the raw listener
#### type RawReader
```go
type RawReader struct {
}
```
RawReader handles incoming raw datagram reception
#### func (*RawReader) Close
```go
func (r *RawReader) Close() error
```
#### func (*RawReader) ReceiveDatagram
```go
func (r *RawReader) ReceiveDatagram() (*RawDatagram, error)
```
ReceiveDatagram receives a raw datagram from any source
#### type RawSession
```go
type RawSession struct {
*common.BaseSession
}
```
RawSession represents a raw session that can send and receive raw datagrams
#### func NewRawSession
```go
func NewRawSession(sam *common.SAM, id string, keys i2pkeys.I2PKeys, options []string) (*RawSession, error)
```
NewRawSession creates a new raw session
#### func (*RawSession) Addr
```go
func (s *RawSession) Addr() i2pkeys.I2PAddr
```
Addr returns the I2P address of this session
#### func (*RawSession) Close
```go
func (s *RawSession) Close() error
```
Close closes the raw session and all associated resources
#### func (*RawSession) Dial
```go
func (rs *RawSession) Dial(destination string) (net.PacketConn, error)
```
Dial establishes a raw connection to the specified destination
#### func (*RawSession) DialContext
```go
func (rs *RawSession) DialContext(ctx context.Context, destination string) (net.PacketConn, error)
```
DialContext establishes a raw connection with context support
#### func (*RawSession) DialI2P
```go
func (rs *RawSession) DialI2P(addr i2pkeys.I2PAddr) (net.PacketConn, error)
```
DialI2P establishes a raw connection to an I2P address
#### func (*RawSession) DialI2PContext
```go
func (rs *RawSession) DialI2PContext(ctx context.Context, addr i2pkeys.I2PAddr) (net.PacketConn, error)
```
DialI2PContext establishes a raw connection to an I2P address with context
support
#### func (*RawSession) DialI2PTimeout
```go
func (rs *RawSession) DialI2PTimeout(addr i2pkeys.I2PAddr, timeout time.Duration) (net.PacketConn, error)
```
DialI2PTimeout establishes a raw connection to an I2P address with timeout
#### func (*RawSession) DialTimeout
```go
func (rs *RawSession) DialTimeout(destination string, timeout time.Duration) (net.PacketConn, error)
```
DialTimeout establishes a raw connection with a timeout
#### func (*RawSession) Listen
```go
func (s *RawSession) Listen() (*RawListener, error)
```
#### func (*RawSession) NewReader
```go
func (s *RawSession) NewReader() *RawReader
```
NewReader creates a RawReader for receiving raw datagrams
#### func (*RawSession) NewWriter
```go
func (s *RawSession) NewWriter() *RawWriter
```
NewWriter creates a RawWriter for sending raw datagrams
#### func (*RawSession) PacketConn
```go
func (s *RawSession) PacketConn() net.PacketConn
```
PacketConn returns a net.PacketConn interface for this session
#### func (*RawSession) ReceiveDatagram
```go
func (s *RawSession) ReceiveDatagram() (*RawDatagram, error)
```
ReceiveDatagram receives a raw datagram from any source
#### func (*RawSession) SendDatagram
```go
func (s *RawSession) SendDatagram(data []byte, dest i2pkeys.I2PAddr) error
```
SendDatagram sends a raw datagram to the specified destination
#### type RawWriter
```go
type RawWriter struct {
}
```
RawWriter handles outgoing raw datagram transmission
#### func (*RawWriter) SendDatagram
```go
func (w *RawWriter) SendDatagram(data []byte, dest i2pkeys.I2PAddr) error
```
SendDatagram sends a raw datagram to the specified destination
#### func (*RawWriter) SetTimeout
```go
func (w *RawWriter) SetTimeout(timeout time.Duration) *RawWriter
```
SetTimeout sets the timeout for raw datagram operations
#### type SAM
```go
type SAM struct {
*common.SAM
}
```
SAM wraps common.SAM to provide raw-specific functionality
#### func (*SAM) NewRawSession
```go
func (s *SAM) NewRawSession(id string, keys i2pkeys.I2PKeys, options []string) (*RawSession, error)
```
NewRawSession creates a new raw session with the SAM bridge
#### func (*SAM) NewRawSessionWithPorts
```go
func (s *SAM) NewRawSessionWithPorts(id, fromPort, toPort string, keys i2pkeys.I2PKeys, options []string) (*RawSession, error)
```
NewRawSessionWithPorts creates a new raw session with port specifications
#### func (*SAM) NewRawSessionWithSignature
```go
func (s *SAM) NewRawSessionWithSignature(id string, keys i2pkeys.I2PKeys, options []string, sigType string) (*RawSession, error)
```
NewRawSessionWithSignature creates a new raw session with custom signature type

252
stream/DOC.md Normal file
View File

@ -0,0 +1,252 @@
# stream
--
import "github.com/go-i2p/go-sam-go/stream"
## Usage
#### type SAM
```go
type SAM struct {
*common.SAM
}
```
SAM wraps common.SAM to provide stream-specific functionality
#### func (*SAM) NewStreamSession
```go
func (s *SAM) NewStreamSession(id string, keys i2pkeys.I2PKeys, options []string) (*StreamSession, error)
```
NewStreamSession creates a new streaming session with the SAM bridge
#### func (*SAM) NewStreamSessionWithPorts
```go
func (s *SAM) NewStreamSessionWithPorts(id, fromPort, toPort string, keys i2pkeys.I2PKeys, options []string) (*StreamSession, error)
```
NewStreamSessionWithPorts creates a new streaming session with port
specifications
#### func (*SAM) NewStreamSessionWithSignature
```go
func (s *SAM) NewStreamSessionWithSignature(id string, keys i2pkeys.I2PKeys, options []string, sigType string) (*StreamSession, error)
```
NewStreamSessionWithSignature creates a new streaming session with custom
signature type
#### type StreamConn
```go
type StreamConn struct {
}
```
StreamConn implements net.Conn for I2P streaming connections
#### func (*StreamConn) Close
```go
func (c *StreamConn) Close() error
```
Close closes the connection
#### func (*StreamConn) LocalAddr
```go
func (c *StreamConn) LocalAddr() net.Addr
```
LocalAddr returns the local network address
#### func (*StreamConn) Read
```go
func (c *StreamConn) Read(b []byte) (int, error)
```
Read reads data from the connection
#### func (*StreamConn) RemoteAddr
```go
func (c *StreamConn) RemoteAddr() net.Addr
```
RemoteAddr returns the remote network address
#### func (*StreamConn) SetDeadline
```go
func (c *StreamConn) SetDeadline(t time.Time) error
```
SetDeadline sets the read and write deadlines
#### func (*StreamConn) SetReadDeadline
```go
func (c *StreamConn) SetReadDeadline(t time.Time) error
```
SetReadDeadline sets the deadline for future Read calls
#### func (*StreamConn) SetWriteDeadline
```go
func (c *StreamConn) SetWriteDeadline(t time.Time) error
```
SetWriteDeadline sets the deadline for future Write calls
#### func (*StreamConn) Write
```go
func (c *StreamConn) Write(b []byte) (int, error)
```
Write writes data to the connection
#### type StreamDialer
```go
type StreamDialer struct {
}
```
StreamDialer handles client-side connection establishment
#### func (*StreamDialer) Dial
```go
func (d *StreamDialer) Dial(destination string) (*StreamConn, error)
```
Dial establishes a connection to the specified destination
#### func (*StreamDialer) DialContext
```go
func (d *StreamDialer) DialContext(ctx context.Context, destination string) (*StreamConn, error)
```
DialContext establishes a connection with context support
#### func (*StreamDialer) DialI2P
```go
func (d *StreamDialer) DialI2P(addr i2pkeys.I2PAddr) (*StreamConn, error)
```
DialI2P establishes a connection to the specified I2P address
#### func (*StreamDialer) DialI2PContext
```go
func (d *StreamDialer) DialI2PContext(ctx context.Context, addr i2pkeys.I2PAddr) (*StreamConn, error)
```
DialI2PContext establishes a connection to an I2P address with context support
#### func (*StreamDialer) SetTimeout
```go
func (d *StreamDialer) SetTimeout(timeout time.Duration) *StreamDialer
```
SetTimeout sets the default timeout for new dialers
#### type StreamListener
```go
type StreamListener struct {
}
```
StreamListener implements net.Listener for I2P streaming connections
#### func (*StreamListener) Accept
```go
func (l *StreamListener) Accept() (net.Conn, error)
```
Accept waits for and returns the next connection to the listener
#### func (*StreamListener) AcceptStream
```go
func (l *StreamListener) AcceptStream() (*StreamConn, error)
```
AcceptStream waits for and returns the next I2P streaming connection
#### func (*StreamListener) Addr
```go
func (l *StreamListener) Addr() net.Addr
```
Addr returns the listener's network address
#### func (*StreamListener) Close
```go
func (l *StreamListener) Close() error
```
Close closes the listener
#### type StreamSession
```go
type StreamSession struct {
*common.BaseSession
}
```
StreamSession represents a streaming session that can create listeners and
dialers
#### func NewStreamSession
```go
func NewStreamSession(sam *common.SAM, id string, keys i2pkeys.I2PKeys, options []string) (*StreamSession, error)
```
NewStreamSession creates a new streaming session
#### func (*StreamSession) Addr
```go
func (s *StreamSession) Addr() i2pkeys.I2PAddr
```
Addr returns the I2P address of this session
#### func (*StreamSession) Close
```go
func (s *StreamSession) Close() error
```
Close closes the streaming session and all associated resources
#### func (*StreamSession) Dial
```go
func (s *StreamSession) Dial(destination string) (*StreamConn, error)
```
Dial establishes a connection to the specified I2P destination
#### func (*StreamSession) DialContext
```go
func (s *StreamSession) DialContext(ctx context.Context, destination string) (*StreamConn, error)
```
DialContext establishes a connection with context support
#### func (*StreamSession) DialI2P
```go
func (s *StreamSession) DialI2P(addr i2pkeys.I2PAddr) (*StreamConn, error)
```
DialI2P establishes a connection to the specified I2P address
#### func (*StreamSession) Listen
```go
func (s *StreamSession) Listen() (*StreamListener, error)
```
Listen creates a StreamListener that accepts incoming connections
#### func (*StreamSession) NewDialer
```go
func (s *StreamSession) NewDialer() *StreamDialer
```
NewDialer creates a StreamDialer for establishing outbound connections