Documentation
¶
Index ¶
- Constants
- Variables
- func DestGenerateMsg(sigType int) []byte
- func ErrCantReachPeer(msg string) error
- func ErrDuplicatedDest(msg string) error
- func ErrDuplicatedID(msg string) error
- func ErrI2PError(msg string) error
- func ErrInvalidID(msg string) error
- func ErrInvalidKey(msg string) error
- func ErrKeyNotFound(msg string) error
- func ErrPeerNotFound(msg string) error
- func ErrTimeout(msg string) error
- func GenerateSessionID(length int) string
- func GetFreePort() (int, error)
- func HelloMsg(minVer, maxVer string) []byte
- func I2PBase64Decode(s string) ([]byte, error)
- func I2PBase64Encode(b []byte) string
- func IsAddressAccessible(addr Address) bool
- func NamingLookupMsg(name string) []byte
- func SessionCreateMsg(style, id, dest, opts string) []byte
- func StreamAcceptMsg(id, silent string) []byte
- func StreamConnect(ctx context.Context, sessionName string, destStr string, samAddr Address) (*SAMSocket, *Destination, error)
- func StreamConnectMsg(id, dest, silent string) []byte
- func StreamForwardMsg(id string, port int, opts string) []byte
- type Address
- type ClientTunnel
- type DefaultSAMClient
- func (c *DefaultSAMClient) CreateStreamSession(ctx context.Context, name, style string, opts map[string]string, ...) (StreamSession, error)
- func (c *DefaultSAMClient) NewDestination(ctx context.Context, dest *Destination) (*Destination, error)
- func (c *DefaultSAMClient) StreamAccept(ctx context.Context, sess StreamSession, samAddr Address) (*IncomingStream, error)
- func (c *DefaultSAMClient) StreamConnect(ctx context.Context, sess StreamSession, remoteDest string, samAddr Address) (net.Conn, error)
- type Destination
- func DestLookup(ctx context.Context, domain string, samAddr Address) (*Destination, error)
- func DestinationFromBase64(b64 string, hasPriv bool) (*Destination, error)
- func NewDestination(data []byte, hasPriv bool) (*Destination, error)
- func NewDestinationSAM(ctx context.Context, samAddr Address, sigType int) (*Destination, error)
- type I2PTunnel
- type IncomingStream
- type PrivateKey
- type SAMClient
- type SAMError
- type SAMMessage
- type SAMSession
- type SAMSocket
- type ServerTunnel
- type StreamSession
- type TunnelStatus
Constants ¶
const ( SAMErrCantReachPeer = "CANT_REACH_PEER" SAMErrDuplicatedDest = "DUPLICATED_DEST" SAMErrDuplicatedID = "DUPLICATED_ID" SAMErrI2PError = "I2P_ERROR" SAMErrInvalidID = "INVALID_ID" SAMErrInvalidKey = "INVALID_KEY" SAMErrKeyNotFound = "KEY_NOT_FOUND" SAMErrPeerNotFound = "PEER_NOT_FOUND" SAMErrTimeout = "TIMEOUT" )
const ( I2PAltChars = "-~" SAMBufSize = 4096 DefaultSAMHost = "127.0.0.1" DefaultSAMPort = 7656 DefaultMinVer = "3.1" DefaultMaxVer = "3.1" TransientDest = "TRANSIENT" SigTypeEd25519 = 7 DefaultSigType = SigTypeEd25519 )
const BufferSize = 65536
Variables ¶
var ( ValidBase32Address = regexp.MustCompile(`^([a-zA-Z0-9]{52}).b32\.i2p$`) ValidBase64Address = regexp.MustCompile(`^([a-zA-Z0-9\-~=]{516,528})$`) )
var DefaultSAMAddress = Address{
Host: "127.0.0.1",
Port: 7656,
}
DefaultSAMAddress — аналог sam.DEFAULT_ADDRESS ("127.0.0.1", 7656)
var SAMExceptionMap = map[string]func(string) error{ SAMErrCantReachPeer: ErrCantReachPeer, SAMErrDuplicatedDest: ErrDuplicatedDest, SAMErrDuplicatedID: ErrDuplicatedID, SAMErrI2PError: ErrI2PError, SAMErrInvalidID: ErrInvalidID, SAMErrInvalidKey: ErrInvalidKey, SAMErrKeyNotFound: ErrKeyNotFound, SAMErrPeerNotFound: ErrPeerNotFound, SAMErrTimeout: ErrTimeout, }
Lookup table — аналог SAM_EXCEPTIONS in Python
Functions ¶
func DestGenerateMsg ¶
func ErrCantReachPeer ¶
func ErrDuplicatedDest ¶
func ErrDuplicatedID ¶
func ErrI2PError ¶
func ErrInvalidID ¶
func ErrInvalidKey ¶
func ErrKeyNotFound ¶
func ErrPeerNotFound ¶
func ErrTimeout ¶
func GenerateSessionID ¶
GenerateSessionID — аналог generate_session_id(), length по умолчанию 6
func I2PBase64Decode ¶
func I2PBase64Encode ¶
func IsAddressAccessible ¶
IsAddressAccessible — аналог is_address_accessible()
func NamingLookupMsg ¶
func SessionCreateMsg ¶
func StreamAcceptMsg ¶
func StreamConnect ¶
func StreamConnect( ctx context.Context, sessionName string, destStr string, samAddr Address, ) (*SAMSocket, *Destination, error)
StreamConnect — аналог stream_connect()
func StreamConnectMsg ¶
Types ¶
type Address ¶
func AddressFromString ¶
AddressFromString — аналог address_from_string("host:port")
type ClientTunnel ¶
type ClientTunnel struct {
*I2PTunnel
RemoteDestination string
Status TunnelStatus
// contains filtered or unexported fields
}
func NewClientTunnel ¶
func NewClientTunnel(local Address, remoteDest string, samAddr Address, samClient SAMClient, dest *Destination, sessionName string, opts map[string]string) *ClientTunnel
func (*ClientTunnel) Run ¶
func (t *ClientTunnel) Run(ctx context.Context) error
Run — аналог async def run(self) у ClientTunnel.
func (*ClientTunnel) Stop ¶
func (t *ClientTunnel) Stop()
type DefaultSAMClient ¶
DefaultSAMClient реализует SAMClient поверх функций из aiosam.go.
func NewDefaultSAMClient ¶
func NewDefaultSAMClient(addr Address) *DefaultSAMClient
func (*DefaultSAMClient) CreateStreamSession ¶
func (c *DefaultSAMClient) CreateStreamSession(ctx context.Context, name, style string, opts map[string]string, dest *Destination, samAddr Address) (StreamSession, error)
func (*DefaultSAMClient) NewDestination ¶
func (c *DefaultSAMClient) NewDestination(ctx context.Context, dest *Destination) (*Destination, error)
func (*DefaultSAMClient) StreamAccept ¶
func (c *DefaultSAMClient) StreamAccept(ctx context.Context, sess StreamSession, samAddr Address) (*IncomingStream, error)
func (*DefaultSAMClient) StreamConnect ¶
func (c *DefaultSAMClient) StreamConnect(ctx context.Context, sess StreamSession, remoteDest string, samAddr Address) (net.Conn, error)
type Destination ¶
type Destination struct {
Data []byte
Base64 string
PrivKey *PrivateKey
}
func DestLookup ¶
DestLookup — аналог dest_lookup()
func DestinationFromBase64 ¶
func DestinationFromBase64(b64 string, hasPriv bool) (*Destination, error)
func NewDestination ¶
func NewDestination(data []byte, hasPriv bool) (*Destination, error)
func NewDestinationSAM ¶
NewDestinationSAM — аналог new_destination()
func (*Destination) Base32 ¶
func (d *Destination) Base32() string
func (*Destination) String ¶
func (d *Destination) String() string
type I2PTunnel ¶
type I2PTunnel struct {
LocalAddress Address
Destination *Destination
SessionName string
Options map[string]string
SAMAddress Address
SAM SAMClient
Session StreamSession
}
func NewI2PTunnel ¶
type IncomingStream ¶
type IncomingStream struct {
Conn net.Conn
DestB64 string // исходный dest как строка
FirstData []byte // первые считанные байты (data после dest\n)
}
IncomingStream — входящее соединение с I2P.
type PrivateKey ¶
func NewPrivateKey ¶
func NewPrivateKey(data []byte) (*PrivateKey, error)
type SAMClient ¶
type SAMClient interface {
NewDestination(ctx context.Context, dest *Destination) (*Destination, error)
CreateStreamSession(ctx context.Context, name, style string, opts map[string]string, dest *Destination, samAddr Address) (StreamSession, error)
StreamConnect(ctx context.Context, sess StreamSession, remoteDest string, samAddr Address) (net.Conn, error)
// для серверного туннеля: принять входящее соединение
StreamAccept(ctx context.Context, sess StreamSession, samAddr Address) (*IncomingStream, error)
}
SAMClient — абстракция поверх SAM API. Реализацию делаешь отдельно.
type SAMMessage ¶
func ParseSAMMessage ¶
func ParseSAMMessage(b []byte) (*SAMMessage, error)
func (*SAMMessage) OK ¶
func (m *SAMMessage) OK() bool
func (*SAMMessage) String ¶
func (m *SAMMessage) String() string
type SAMSession ¶
type SAMSession struct {
ID string
Socket *SAMSocket
Destination *Destination
}
SAMSession — аналог create_session() + Session context manager
func CreateSession ¶
func CreateSession( ctx context.Context, sessionName string, samAddr Address, style string, sigType int, dest *Destination, options map[string]string, ) (*SAMSession, error)
CreateSession — аналог create_session()
func (*SAMSession) Close ¶
func (s *SAMSession) Close() error
func (*SAMSession) Name ¶
func (s *SAMSession) Name() string
type SAMSocket ¶
SAMSocket — аналог (reader, writer)
func GetSAMSocket ¶
GetSAMSocket — аналог get_sam_socket()
type ServerTunnel ¶
type ServerTunnel struct {
*I2PTunnel
Status TunnelStatus
// contains filtered or unexported fields
}
func NewServerTunnel ¶
func NewServerTunnel(local Address, samAddr Address, samClient SAMClient, dest *Destination, sessionName string, opts map[string]string) *ServerTunnel
func (*ServerTunnel) Stop ¶
func (t *ServerTunnel) Stop()
type StreamSession ¶
StreamSession — сессия STREAM в SAM.
type TunnelStatus ¶
TunnelStatus — аналог self.status из Python.