19 KiB
common
-- import "github.com/go-i2p/go-sam-go/common"
Usage
const (
DEFAULT_SAM_MIN = "3.1"
DEFAULT_SAM_MAX = "3.3"
)
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="
)
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
)
const (
SAM_RESULT_OK = "RESULT=OK"
SAM_RESULT_INVALID_KEY = "RESULT=INVALID_KEY"
SAM_RESULT_KEY_NOT_FOUND = "RESULT=KEY_NOT_FOUND"
)
const (
HELLO_REPLY_OK = "HELLO REPLY RESULT=OK"
HELLO_REPLY_NOVERSION = "HELLO REPLY RESULT=NOVERSION\n"
)
const (
SESSION_STYLE_STREAM = "STREAM"
SESSION_STYLE_DATAGRAM = "DATAGRAM"
SESSION_STYLE_RAW = "RAW"
)
const (
ACCESS_TYPE_WHITELIST = "whitelist"
ACCESS_TYPE_BLACKLIST = "blacklist"
ACCESS_TYPE_NONE = "none"
)
func ExtractDest
func ExtractDest(input string) string
func ExtractPairInt
func ExtractPairInt(input, value string) int
func ExtractPairString
func ExtractPairString(input, value string) string
func IgnorePortError
func IgnorePortError(err error) error
func RandPort
func RandPort() (portNumber string, err error)
func SetAccessList
func SetAccessList(s []string) func(*SAMEmit) error
SetAccessList tells the system to treat the AccessList as a whitelist
func SetAccessListType
func SetAccessListType(s string) func(*SAMEmit) error
SetAccessListType tells the system to treat the AccessList as a whitelist
func SetAllowZeroIn
func SetAllowZeroIn(b bool) func(*SAMEmit) error
SetAllowZeroIn tells the tunnel to accept zero-hop peers
func SetAllowZeroOut
func SetAllowZeroOut(b bool) func(*SAMEmit) error
SetAllowZeroOut tells the tunnel to accept zero-hop peers
func SetCloseIdle
func SetCloseIdle(b bool) func(*SAMEmit) error
SetCloseIdle tells the connection to close it's tunnels during extended idle time.
func SetCloseIdleTime
func SetCloseIdleTime(u int) func(*SAMEmit) error
SetCloseIdleTime sets the time to wait before closing tunnels to idle levels
func SetCloseIdleTimeMs
func SetCloseIdleTimeMs(u int) func(*SAMEmit) error
SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds
func SetCompress
func SetCompress(b bool) func(*SAMEmit) error
SetCompress tells clients to use compression
func SetEncrypt
func SetEncrypt(b bool) func(*SAMEmit) error
SetEncrypt tells the router to use an encrypted leaseset
func SetFastRecieve
func SetFastRecieve(b bool) func(*SAMEmit) error
SetFastRecieve tells clients to use compression
func SetInBackups
func SetInBackups(u int) func(*SAMEmit) error
SetInBackups sets the inbound tunnel backups
func SetInLength
func SetInLength(u int) func(*SAMEmit) error
SetInLength sets the number of hops inbound
func SetInQuantity
func SetInQuantity(u int) func(*SAMEmit) error
SetInQuantity sets the inbound tunnel quantity
func SetInVariance
func SetInVariance(i int) func(*SAMEmit) error
SetInVariance sets the variance of a number of hops inbound
func SetLeaseSetKey
func SetLeaseSetKey(s string) func(*SAMEmit) error
SetLeaseSetKey sets the host of the SAMEmit's SAM bridge
func SetLeaseSetPrivateKey
func SetLeaseSetPrivateKey(s string) func(*SAMEmit) error
SetLeaseSetPrivateKey sets the host of the SAMEmit's SAM bridge
func SetLeaseSetPrivateSigningKey
func SetLeaseSetPrivateSigningKey(s string) func(*SAMEmit) error
SetLeaseSetPrivateSigningKey sets the host of the SAMEmit's SAM bridge
func SetMessageReliability
func SetMessageReliability(s string) func(*SAMEmit) error
SetMessageReliability sets the host of the SAMEmit's SAM bridge
func SetName
func SetName(s string) func(*SAMEmit) error
SetName sets the host of the SAMEmit's SAM bridge
func SetOutBackups
func SetOutBackups(u int) func(*SAMEmit) error
SetOutBackups sets the inbound tunnel backups
func SetOutLength
func SetOutLength(u int) func(*SAMEmit) error
SetOutLength sets the number of hops outbound
func SetOutQuantity
func SetOutQuantity(u int) func(*SAMEmit) error
SetOutQuantity sets the outbound tunnel quantity
func SetOutVariance
func SetOutVariance(i int) func(*SAMEmit) error
SetOutVariance sets the variance of a number of hops outbound
func SetReduceIdle
func SetReduceIdle(b bool) func(*SAMEmit) error
SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.
func SetReduceIdleQuantity
func SetReduceIdleQuantity(u int) func(*SAMEmit) error
SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time
func SetReduceIdleTime
func SetReduceIdleTime(u int) func(*SAMEmit) error
SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels
func SetReduceIdleTimeMs
func SetReduceIdleTimeMs(u int) func(*SAMEmit) error
SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds
func SetSAMAddress
func SetSAMAddress(s string) func(*SAMEmit) error
SetSAMAddress sets the SAM address all-at-once
func SetSAMHost
func SetSAMHost(s string) func(*SAMEmit) error
SetSAMHost sets the host of the SAMEmit's SAM bridge
func SetSAMPort
func SetSAMPort(s string) func(*SAMEmit) error
SetSAMPort sets the port of the SAMEmit's SAM bridge using a string
func SetType
func SetType(s string) func(*SAMEmit) error
SetType sets the type of the forwarder server
func SplitHostPort
func SplitHostPort(hostport string) (string, string, error)
type BaseSession
type BaseSession struct {
SAM SAM
}
func (*BaseSession) Close
func (bs *BaseSession) Close() error
func (*BaseSession) From
func (bs *BaseSession) From() string
func (*BaseSession) ID
func (bs *BaseSession) ID() string
func (*BaseSession) Keys
func (bs *BaseSession) Keys() i2pkeys.I2PKeys
func (*BaseSession) LocalAddr
func (bs *BaseSession) LocalAddr() net.Addr
func (*BaseSession) Read
func (bs *BaseSession) Read(b []byte) (int, error)
func (*BaseSession) RemoteAddr
func (bs *BaseSession) RemoteAddr() net.Addr
func (*BaseSession) SetDeadline
func (bs *BaseSession) SetDeadline(t time.Time) error
func (*BaseSession) SetReadDeadline
func (bs *BaseSession) SetReadDeadline(t time.Time) error
func (*BaseSession) SetWriteDeadline
func (bs *BaseSession) SetWriteDeadline(t time.Time) error
func (*BaseSession) To
func (bs *BaseSession) To() string
func (*BaseSession) Write
func (bs *BaseSession) Write(b []byte) (int, error)
type I2PConfig
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
func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error)
func (*I2PConfig) Accesslist
func (f *I2PConfig) Accesslist() string
Accesslist generates the I2CP access list configuration string based on the configured access list
func (*I2PConfig) Accesslisttype
func (f *I2PConfig) Accesslisttype() string
Accesslisttype returns the I2CP access list configuration string based on the AccessListType setting
func (*I2PConfig) Close
func (f *I2PConfig) Close() string
Close returns I2CP close-on-idle configuration settings as a string if enabled
func (*I2PConfig) DestinationKey
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
func (f *I2PConfig) DoZero() string
DoZero returns the zero hop and fast receive configuration string settings
func (*I2PConfig) EncryptLease
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
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
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
func (f *I2PConfig) InboundBackupQuantity() string
func (*I2PConfig) InboundLength
func (f *I2PConfig) InboundLength() string
func (*I2PConfig) InboundLengthVariance
func (f *I2PConfig) InboundLengthVariance() string
func (*I2PConfig) InboundQuantity
func (f *I2PConfig) InboundQuantity() string
func (*I2PConfig) LeaseSetEncryptionType
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
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
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
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
func (f *I2PConfig) OutboundBackupQuantity() string
func (*I2PConfig) OutboundLength
func (f *I2PConfig) OutboundLength() string
func (*I2PConfig) OutboundLengthVariance
func (f *I2PConfig) OutboundLengthVariance() string
func (*I2PConfig) OutboundQuantity
func (f *I2PConfig) OutboundQuantity() string
func (*I2PConfig) Print
func (f *I2PConfig) Print() []string
Print returns a slice of strings containing all the I2P configuration settings
func (*I2PConfig) Reduce
func (f *I2PConfig) Reduce() string
Reduce returns I2CP reduce-on-idle configuration settings as a string if enabled
func (*I2PConfig) Reliability
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
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
func (f *I2PConfig) Sam() string
Sam returns the SAM bridge address as a string in the format "host:port"
func (*I2PConfig) SessionStyle
func (f *I2PConfig) SessionStyle() string
SessionStyle returns the SAM session style configuration string If no style is set, defaults to "STREAM"
func (*I2PConfig) SetSAMAddress
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
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
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
func (f *I2PConfig) UsingCompression() string
type Option
type Option func(*SAMEmit) error
Option is a SAMEmit Option
type Options
type Options map[string]string
options map
func (Options) AsList
func (opts Options) AsList() (ls []string)
obtain sam options as list of strings
type SAM
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
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
func (sam *SAM) Close() error
close this sam session
func (*SAM) EnsureKeyfile
func (sam *SAM) EnsureKeyfile(fname string) (keys i2pkeys.I2PKeys, err error)
if keyfile fname does not exist
func (*SAM) Keys
func (sam *SAM) Keys() (k *i2pkeys.I2PKeys)
func (*SAM) Lookup
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
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
func (sam SAM) NewGenericSessionWithSignature(style, id string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error)
func (SAM) NewGenericSessionWithSignatureAndPorts
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
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
func (sam *SAM) ReadKeys(r io.Reader) (err error)
read public/private keys from an io.Reader
type SAMEmit
type SAMEmit struct {
I2PConfig
}
func NewEmit
func NewEmit(opts ...func(*SAMEmit) error) (*SAMEmit, error)
func (*SAMEmit) Accept
func (e *SAMEmit) Accept() string
func (*SAMEmit) AcceptBytes
func (e *SAMEmit) AcceptBytes() []byte
func (*SAMEmit) Connect
func (e *SAMEmit) Connect(dest string) string
func (*SAMEmit) ConnectBytes
func (e *SAMEmit) ConnectBytes(dest string) []byte
func (*SAMEmit) Create
func (e *SAMEmit) Create() string
func (*SAMEmit) CreateBytes
func (e *SAMEmit) CreateBytes() []byte
func (*SAMEmit) GenerateDestination
func (e *SAMEmit) GenerateDestination() string
func (*SAMEmit) GenerateDestinationBytes
func (e *SAMEmit) GenerateDestinationBytes() []byte
func (*SAMEmit) Hello
func (e *SAMEmit) Hello() string
func (*SAMEmit) HelloBytes
func (e *SAMEmit) HelloBytes() []byte
func (*SAMEmit) Lookup
func (e *SAMEmit) Lookup(name string) string
func (*SAMEmit) LookupBytes
func (e *SAMEmit) LookupBytes(name string) []byte
func (*SAMEmit) SamOptionsString
func (e *SAMEmit) SamOptionsString() string
type SAMResolver
type SAMResolver struct {
*SAM
}
func NewFullSAMResolver
func NewFullSAMResolver(address string) (*SAMResolver, error)
func NewSAMResolver
func NewSAMResolver(parent *SAM) (*SAMResolver, error)
func (*SAMResolver) Resolve
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
type Session interface {
net.Conn
ID() string
Keys() i2pkeys.I2PKeys
Close() error
}