sam3

package module
v0.33.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: Unlicense Imports: 15 Imported by: 27

README

README

!!IMPORTANT!!

In the next version, I'll be moving the i2pkeys directory to it's own repository so I can avoid import cycle headaches. Please migrate to the new i2pkeys repository before upgrading your sam3 dependencies. You can probably do this by running:

find . -name '*.go' -exec sed -i 's|github.com/eyedeekay/sam3/i2pkeys|github.com/eyedeekay/i2pkeys|g' {} \;

STATUS: This project is maintained. I will respond to issues, pull requests, and feature requests within a few days.

README

go library for the I2P SAMv3.0 bridge, used to build anonymous/pseudonymous end-to-end encrypted sockets.

This library is much better than ccondom (that use BOB), much more stable and much easier to maintain.

Support/TODO

What works:

  • Utils
    • Resolving domain names to I2P destinations
    • .b32.i2p hashes
    • Generating keys/i2p destinations
  • Streaming
    • DialI2P() - Connecting to stuff in I2P
    • Listen()/Accept() - Handling incomming connections
    • Implements net.Conn and net.Listener
  • Datagrams
    • Implements net.PacketConn
  • Raw datagrams
    • Like datagrams, but without addresses

Does not work:

  • Stream Forwarding
  • Probably needs some real-world testing

Documentation

  • Latest version-documentation:
    • set your GOPATH
    • Enter godoc -http=:8081 into your terminal and hit enter.
    • Goto http://localhost:8081, click packages, and navigate to sam3

Examples

package main

import (
	"github.com/eyedeekay/sam3"
	"github.com/eyedeekay/sam3/i2pkeys"
	"fmt"
)

const yoursam = "127.0.0.1:7656" // sam bridge

func client(server i2pkeys.I2PAddr) {
	sam, _ := sam3.NewSAM(yoursam)
	keys, _ := sam.NewKeys()
	stream, _ := sam.NewStreamSession("clientTun", keys, sam3.Options_Small)
	fmt.Println("Client: Connecting to " + server.Base32())
	conn, _ := stream.DialI2P(server)
	conn.Write([]byte("Hello world!"))
	return
}

func main() {
	sam, _ := NewSAM(yoursam)
	keys, _ := sam.NewKeys()
	stream, _ := sam.NewStreamSession("serverTun", keys, sam3.Options_Medium)
	listener, _ := stream.Listen()
	go client(keys.Addr())
	conn, _ := listener.Accept()
	buf := make([]byte, 4096)
	n, _ := conn.Read(buf)
	fmt.Println("Server received: " + string(buf[:n]))
}

The above will write to the terminal:

Client: Connecting to zjnvfh4hs3et5vtz35ogwzrws26zvwkcad5uo5esecvg4qpk5b4a.b32.i2p
Server received: Hello world!

Error handling was omitted in the above code for readability.

Testing

  • go test -tags=nettest runs the whole suite (takes 90+ sec to perform!)
  • go test -short runs the shorter variant, does not connect to anything

License

Public domain.

Author

  • Kalle Vedin kalle.vedin@fripost.org
  • Unknown Name (majestrate)
  • idk
  • qiwenmin

Documentation

Overview

Library for I2Ps SAMv3 bridge (https://geti2p.com)

Index

Examples

Constants

View Source
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"
)

Variables

View Source
var (
	// Suitable options if you are shuffling A LOT of traffic. If unused, this
	// will waste your resources.
	Options_Humongous = []string{"inbound.length=3", "outbound.length=3",
		"inbound.lengthVariance=1", "outbound.lengthVariance=1",
		"inbound.backupQuantity=3", "outbound.backupQuantity=3",
		"inbound.quantity=6", "outbound.quantity=6"}

	// Suitable for shuffling a lot of traffic.
	Options_Large = []string{"inbound.length=3", "outbound.length=3",
		"inbound.lengthVariance=1", "outbound.lengthVariance=1",
		"inbound.backupQuantity=1", "outbound.backupQuantity=1",
		"inbound.quantity=4", "outbound.quantity=4"}

	// Suitable for shuffling a lot of traffic quickly with minimum
	// anonymity. Uses 1 hop and multiple tunnels.
	Options_Wide = []string{"inbound.length=1", "outbound.length=1",
		"inbound.lengthVariance=1", "outbound.lengthVariance=1",
		"inbound.backupQuantity=2", "outbound.backupQuantity=2",
		"inbound.quantity=3", "outbound.quantity=3"}

	// Suitable for shuffling medium amounts of traffic.
	Options_Medium = []string{"inbound.length=3", "outbound.length=3",
		"inbound.lengthVariance=1", "outbound.lengthVariance=1",
		"inbound.backupQuantity=0", "outbound.backupQuantity=0",
		"inbound.quantity=2", "outbound.quantity=2"}

	// Sensible defaults for most people
	Options_Default = []string{"inbound.length=3", "outbound.length=3",
		"inbound.lengthVariance=0", "outbound.lengthVariance=0",
		"inbound.backupQuantity=1", "outbound.backupQuantity=1",
		"inbound.quantity=1", "outbound.quantity=1"}

	// Suitable only for small dataflows, and very short lasting connections:
	// You only have one tunnel in each direction, so if any of the nodes
	// through which any of your two tunnels pass through go offline, there will
	// be a complete halt in the dataflow, until a new tunnel is built.
	Options_Small = []string{"inbound.length=3", "outbound.length=3",
		"inbound.lengthVariance=1", "outbound.lengthVariance=1",
		"inbound.backupQuantity=0", "outbound.backupQuantity=0",
		"inbound.quantity=1", "outbound.quantity=1"}

	// Does not use any anonymization, you connect directly to others tunnel
	// endpoints, thus revealing your identity but not theirs. Use this only
	// if you don't care.
	Options_Warning_ZeroHop = []string{"inbound.length=0", "outbound.length=0",
		"inbound.lengthVariance=0", "outbound.lengthVariance=0",
		"inbound.backupQuantity=0", "outbound.backupQuantity=0",
		"inbound.quantity=2", "outbound.quantity=2"}
)

Examples and suggestions for options when creating sessions.

View Source
var PrimarySessionSwitch string = PrimarySessionString()
View Source
var SAM_HOST = getEnv("sam_host", "127.0.0.1")
View Source
var SAM_PORT = getEnv("sam_port", "7656")

Functions

func ExtractDest

func ExtractDest(input string) string

func ExtractPairInt

func ExtractPairInt(input, value string) int

func ExtractPairString

func ExtractPairString(input, value string) string

func GenerateOptionString added in v0.33.7

func GenerateOptionString(opts []string) string

func IgnorePortError added in v0.33.2

func IgnorePortError(err error) error

func PrimarySessionString added in v0.33.2

func PrimarySessionString() string

func RandString added in v0.33.2

func RandString() string

func SAMDefaultAddr added in v0.33.3

func SAMDefaultAddr(fallforward string) string

func SetAccessList added in v0.32.32

func SetAccessList(s []string) func(*SAMEmit) error

SetAccessList tells the system to treat the AccessList as a whitelist

func SetAccessListType added in v0.32.32

func SetAccessListType(s string) func(*SAMEmit) error

SetAccessListType tells the system to treat the AccessList as a whitelist

func SetAllowZeroIn added in v0.32.32

func SetAllowZeroIn(b bool) func(*SAMEmit) error

SetAllowZeroIn tells the tunnel to accept zero-hop peers

func SetAllowZeroOut added in v0.32.32

func SetAllowZeroOut(b bool) func(*SAMEmit) error

SetAllowZeroOut tells the tunnel to accept zero-hop peers

func SetCloseIdle added in v0.32.32

func SetCloseIdle(b bool) func(*SAMEmit) error

SetCloseIdle tells the connection to close it's tunnels during extended idle time.

func SetCloseIdleTime added in v0.32.32

func SetCloseIdleTime(u int) func(*SAMEmit) error

SetCloseIdleTime sets the time to wait before closing tunnels to idle levels

func SetCloseIdleTimeMs added in v0.32.32

func SetCloseIdleTimeMs(u int) func(*SAMEmit) error

SetCloseIdleTimeMs sets the time to wait before closing tunnels to idle levels in milliseconds

func SetCompress added in v0.32.32

func SetCompress(b bool) func(*SAMEmit) error

SetCompress tells clients to use compression

func SetEncrypt added in v0.32.32

func SetEncrypt(b bool) func(*SAMEmit) error

SetEncrypt tells the router to use an encrypted leaseset

func SetFastRecieve added in v0.32.32

func SetFastRecieve(b bool) func(*SAMEmit) error

SetFastRecieve tells clients to use compression

func SetInBackups added in v0.32.32

func SetInBackups(u int) func(*SAMEmit) error

SetInBackups sets the inbound tunnel backups

func SetInLength added in v0.32.32

func SetInLength(u int) func(*SAMEmit) error

SetInLength sets the number of hops inbound

func SetInQuantity added in v0.32.32

func SetInQuantity(u int) func(*SAMEmit) error

SetInQuantity sets the inbound tunnel quantity

func SetInVariance added in v0.32.32

func SetInVariance(i int) func(*SAMEmit) error

SetInVariance sets the variance of a number of hops inbound

func SetLeaseSetKey added in v0.32.32

func SetLeaseSetKey(s string) func(*SAMEmit) error

SetLeaseSetKey sets the host of the SAMEmit's SAM bridge

func SetLeaseSetPrivateKey added in v0.32.32

func SetLeaseSetPrivateKey(s string) func(*SAMEmit) error

SetLeaseSetPrivateKey sets the host of the SAMEmit's SAM bridge

func SetLeaseSetPrivateSigningKey added in v0.32.32

func SetLeaseSetPrivateSigningKey(s string) func(*SAMEmit) error

SetLeaseSetPrivateSigningKey sets the host of the SAMEmit's SAM bridge

func SetMessageReliability added in v0.32.32

func SetMessageReliability(s string) func(*SAMEmit) error

SetMessageReliability sets the host of the SAMEmit's SAM bridge

func SetName added in v0.32.32

func SetName(s string) func(*SAMEmit) error

SetName sets the host of the SAMEmit's SAM bridge

func SetOutBackups added in v0.32.32

func SetOutBackups(u int) func(*SAMEmit) error

SetOutBackups sets the inbound tunnel backups

func SetOutLength added in v0.32.32

func SetOutLength(u int) func(*SAMEmit) error

SetOutLength sets the number of hops outbound

func SetOutQuantity added in v0.32.32

func SetOutQuantity(u int) func(*SAMEmit) error

SetOutQuantity sets the outbound tunnel quantity

func SetOutVariance added in v0.32.32

func SetOutVariance(i int) func(*SAMEmit) error

SetOutVariance sets the variance of a number of hops outbound

func SetReduceIdle added in v0.32.32

func SetReduceIdle(b bool) func(*SAMEmit) error

SetReduceIdle tells the connection to reduce it's tunnels during extended idle time.

func SetReduceIdleQuantity added in v0.32.32

func SetReduceIdleQuantity(u int) func(*SAMEmit) error

SetReduceIdleQuantity sets minimum number of tunnels to reduce to during idle time

func SetReduceIdleTime added in v0.32.32

func SetReduceIdleTime(u int) func(*SAMEmit) error

SetReduceIdleTime sets the time to wait before reducing tunnels to idle levels

func SetReduceIdleTimeMs added in v0.32.32

func SetReduceIdleTimeMs(u int) func(*SAMEmit) error

SetReduceIdleTimeMs sets the time to wait before reducing tunnels to idle levels in milliseconds

func SetSAMAddress added in v0.32.32

func SetSAMAddress(s string) func(*SAMEmit) error

SetSAMAddress sets the SAM address all-at-once

func SetSAMHost added in v0.32.32

func SetSAMHost(s string) func(*SAMEmit) error

SetSAMHost sets the host of the SAMEmit's SAM bridge

func SetSAMPort added in v0.32.32

func SetSAMPort(s string) func(*SAMEmit) error

SetSAMPort sets the port of the SAMEmit's SAM bridge using a string

func SetType added in v0.32.32

func SetType(s string) func(*SAMEmit) error

SetType sets the type of the forwarder server

func SplitHostPort added in v0.33.3

func SplitHostPort(hostport string) (string, string, error)

Types

type Config

type Config struct {
	Addr    string
	Opts    Options
	Session string
	Keyfile string
}

Config is the config type for the sam connector api for i2p which allows applications to 'speak' with i2p

func (*Config) DatagramSession

func (cfg *Config) DatagramSession() (session *DatagramSession, err error)

create new sam datagram session from config

func (*Config) StreamSession

func (cfg *Config) StreamSession() (session *StreamSession, err error)

create new sam connector from config with a stream session

type DatagramSession

type DatagramSession struct {
	// contains filtered or unexported fields
}

The DatagramSession implements net.PacketConn. It works almost like ordinary UDP, except that datagrams may be at most 31kB large. These datagrams are also end-to-end encrypted, signed and includes replay-protection. And they are also built to be surveillance-resistant (yey!).

Example
// Creates a new DatagramSession, which behaves just like a net.PacketConn.

const samBridge = "127.0.0.1:7656"

sam, err := NewSAM(samBridge)
if err != nil {
	fmt.Println(err.Error())
	return
}
keys, err := sam.NewKeys()
if err != nil {
	fmt.Println(err.Error())
	return
}
myself := keys.Addr()

// See the example Option_* variables.
dg, err := sam.NewDatagramSession("DGTUN", keys, Options_Small, 0)
if err != nil {
	fmt.Println(err.Error())
	return
}
someone, err := sam.Lookup("zzz.i2p")
if err != nil {
	fmt.Println(err.Error())
	return
}

dg.WriteTo([]byte("Hello stranger!"), someone)
dg.WriteTo([]byte("Hello myself!"), myself)

buf := make([]byte, 31*1024)
n, _, err := dg.ReadFrom(buf)
if err != nil {
	fmt.Println(err.Error())
	return
}
log.Println("Got message: '" + string(buf[:n]) + "'")
fmt.Println("Got message: " + string(buf[:n]))

return
Output:

Got message: Hello myself!

func (*DatagramSession) Accept added in v0.32.32

func (s *DatagramSession) Accept() (net.Conn, error)

func (*DatagramSession) Addr added in v0.32.32

func (s *DatagramSession) Addr() net.Addr

func (*DatagramSession) B32

func (s *DatagramSession) B32() string

func (*DatagramSession) Close

func (s *DatagramSession) Close() error

Closes the DatagramSession. Implements net.PacketConn

func (*DatagramSession) Dial added in v0.33.2

func (s *DatagramSession) Dial(net string, addr string) (*DatagramSession, error)

func (*DatagramSession) DialI2PRemote added in v0.33.2

func (s *DatagramSession) DialI2PRemote(net string, addr net.Addr) (*DatagramSession, error)

func (*DatagramSession) DialRemote added in v0.33.2

func (s *DatagramSession) DialRemote(net, addr string) (net.PacketConn, error)

func (*DatagramSession) LocalAddr

func (s *DatagramSession) LocalAddr() net.Addr

Implements net.PacketConn

func (*DatagramSession) LocalI2PAddr

func (s *DatagramSession) LocalI2PAddr() i2pkeys.I2PAddr

Returns the I2P destination of the DatagramSession.

func (*DatagramSession) Lookup

func (s *DatagramSession) Lookup(name string) (a net.Addr, err error)

func (*DatagramSession) Read

func (s *DatagramSession) Read(b []byte) (n int, err error)

func (*DatagramSession) ReadFrom

func (s *DatagramSession) ReadFrom(b []byte) (n int, addr net.Addr, err error)

Reads one datagram sent to the destination of the DatagramSession. Returns the number of bytes read, from what address it was sent, or an error. implements net.PacketConn

func (*DatagramSession) RemoteAddr

func (s *DatagramSession) RemoteAddr() net.Addr

func (*DatagramSession) SetDeadline

func (s *DatagramSession) SetDeadline(t time.Time) error

Sets read and write deadlines for the DatagramSession. Implements net.PacketConn and does the same thing. Setting write deadlines for datagrams is seldom done.

func (*DatagramSession) SetReadDeadline

func (s *DatagramSession) SetReadDeadline(t time.Time) error

Sets read deadline for the DatagramSession. Implements net.PacketConn

func (*DatagramSession) SetWriteBuffer

func (s *DatagramSession) SetWriteBuffer(bytes int) error

func (*DatagramSession) SetWriteDeadline

func (s *DatagramSession) SetWriteDeadline(t time.Time) error

Sets the write deadline for the DatagramSession. Implements net.Packetconn.

func (*DatagramSession) Write

func (s *DatagramSession) Write(b []byte) (int, error)

func (*DatagramSession) WriteTo

func (s *DatagramSession) WriteTo(b []byte, addr net.Addr) (n int, err error)

Sends one signed datagram to the destination specified. At the time of writing, maximum size is 31 kilobyte, but this may change in the future. Implements net.PacketConn.

type I2PConfig added in v0.32.32

type I2PConfig struct {
	SamHost string
	SamPort string
	TunName string

	SamMin string
	SamMax string

	Fromport string
	Toport   string

	Style   string
	TunType string

	DestinationKeys i2pkeys.I2PKeys

	SigType                   string
	EncryptLeaseSet           string
	LeaseSetKey               string
	LeaseSetPrivateKey        string
	LeaseSetPrivateSigningKey string
	LeaseSetKeys              i2pkeys.I2PKeys
	InAllowZeroHop            string
	OutAllowZeroHop           string
	InLength                  string
	OutLength                 string
	InQuantity                string
	OutQuantity               string
	InVariance                string
	OutVariance               string
	InBackupQuantity          string
	OutBackupQuantity         string
	FastRecieve               string
	UseCompression            string
	MessageReliability        string
	CloseIdle                 string
	CloseIdleTime             string
	ReduceIdle                string
	ReduceIdleTime            string
	ReduceIdleQuantity        string
	LeaseSetEncryption        string

	//Streaming Library options
	AccessListType string
	AccessList     []string
}

I2PConfig is a struct which manages I2P configuration options

func NewConfig added in v0.32.32

func NewConfig(opts ...func(*I2PConfig) error) (*I2PConfig, error)

func (*I2PConfig) Accesslist added in v0.32.32

func (f *I2PConfig) Accesslist() string

func (*I2PConfig) Accesslisttype added in v0.32.32

func (f *I2PConfig) Accesslisttype() string

func (*I2PConfig) Close added in v0.32.32

func (f *I2PConfig) Close() string

func (*I2PConfig) DestinationKey added in v0.32.32

func (f *I2PConfig) DestinationKey() string

func (*I2PConfig) DoZero added in v0.32.32

func (f *I2PConfig) DoZero() string

func (*I2PConfig) EncryptLease added in v0.32.32

func (f *I2PConfig) EncryptLease() string

func (*I2PConfig) FromPort added in v0.32.32

func (f *I2PConfig) FromPort() string

func (*I2PConfig) ID added in v0.32.32

func (f *I2PConfig) ID() string

func (*I2PConfig) LeaseSetEncryptionType added in v0.33.7

func (f *I2PConfig) LeaseSetEncryptionType() string

func (*I2PConfig) Leasesetsettings added in v0.32.32

func (f *I2PConfig) Leasesetsettings() (string, string, string)

func (*I2PConfig) MaxSAM added in v0.32.32

func (f *I2PConfig) MaxSAM() string

func (*I2PConfig) MinSAM added in v0.32.32

func (f *I2PConfig) MinSAM() string

func (*I2PConfig) Print added in v0.32.32

func (f *I2PConfig) Print() []string

func (*I2PConfig) Reduce added in v0.32.32

func (f *I2PConfig) Reduce() string

func (*I2PConfig) Reliability added in v0.32.32

func (f *I2PConfig) Reliability() string

func (*I2PConfig) Sam added in v0.32.32

func (f *I2PConfig) Sam() string

func (*I2PConfig) SessionStyle added in v0.32.32

func (f *I2PConfig) SessionStyle() string

func (*I2PConfig) SetSAMAddress added in v0.32.32

func (f *I2PConfig) SetSAMAddress(addr string)

func (*I2PConfig) SignatureType added in v0.32.32

func (f *I2PConfig) SignatureType() string

func (*I2PConfig) ToPort added in v0.32.32

func (f *I2PConfig) ToPort() string

type Option added in v0.32.32

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 PrimarySession added in v0.33.2

type PrimarySession struct {
	Timeout  time.Duration
	Deadline time.Time

	Config SAMEmit
	// contains filtered or unexported fields
}

Represents a primary session.

func (*PrimarySession) Addr added in v0.33.2

func (ss *PrimarySession) Addr() i2pkeys.I2PAddr

Returns the I2P destination (the address) of the stream session

func (*PrimarySession) Close added in v0.33.2

func (ss *PrimarySession) Close() error

func (*PrimarySession) Dial added in v0.33.2

func (sam *PrimarySession) Dial(network, addr string) (net.Conn, error)

func (*PrimarySession) DialTCP added in v0.33.2

func (sam *PrimarySession) DialTCP(network string, laddr, raddr net.Addr) (net.Conn, error)

DialTCP implements x/dialer

func (*PrimarySession) DialTCPI2P added in v0.33.2

func (sam *PrimarySession) DialTCPI2P(network string, laddr, raddr string) (net.Conn, error)

func (*PrimarySession) DialUDP added in v0.33.2

func (sam *PrimarySession) DialUDP(network string, laddr, raddr net.Addr) (net.PacketConn, error)

DialUDP implements x/dialer

func (*PrimarySession) DialUDPI2P added in v0.33.2

func (sam *PrimarySession) DialUDPI2P(network, laddr, raddr string) (*DatagramSession, error)

func (*PrimarySession) From added in v0.33.2

func (ss *PrimarySession) From() string

func (*PrimarySession) ID added in v0.33.2

func (ss *PrimarySession) ID() string

Returns the local tunnel name of the I2P tunnel used for the stream session

func (*PrimarySession) Keys added in v0.33.2

func (ss *PrimarySession) Keys() i2pkeys.I2PKeys

Returns the keys associated with the stream session

func (*PrimarySession) LocalAddr added in v0.33.2

func (ss *PrimarySession) LocalAddr() net.Addr

func (*PrimarySession) Lookup added in v0.33.2

func (s *PrimarySession) Lookup(name string) (a net.Addr, err error)

func (*PrimarySession) NewDatagramSubSession added in v0.33.2

func (s *PrimarySession) NewDatagramSubSession(id string, udpPort int) (*DatagramSession, error)

Creates a new datagram session. udpPort is the UDP port SAM is listening on, and if you set it to zero, it will use SAMs standard UDP port.

func (*PrimarySession) NewRawSubSession added in v0.33.2

func (s *PrimarySession) NewRawSubSession(id string, udpPort int) (*RawSession, error)

Creates a new raw session. udpPort is the UDP port SAM is listening on, and if you set it to zero, it will use SAMs standard UDP port.

func (*PrimarySession) NewStreamSubSession added in v0.33.2

func (sam *PrimarySession) NewStreamSubSession(id string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*PrimarySession) NewStreamSubSessionWithPorts added in v0.33.2

func (sam *PrimarySession) NewStreamSubSessionWithPorts(id, from, to string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*PrimarySession) NewUniqueStreamSubSession added in v0.33.2

func (sam *PrimarySession) NewUniqueStreamSubSession(id string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*PrimarySession) Resolve added in v0.33.2

func (sam *PrimarySession) Resolve(network, addr string) (net.Addr, error)

func (*PrimarySession) ResolveTCPAddr added in v0.33.2

func (sam *PrimarySession) ResolveTCPAddr(network, dest string) (net.Addr, error)

func (*PrimarySession) ResolveUDPAddr added in v0.33.2

func (sam *PrimarySession) ResolveUDPAddr(network, dest string) (net.Addr, error)

func (*PrimarySession) SignatureType added in v0.33.2

func (ss *PrimarySession) SignatureType() string

func (*PrimarySession) To added in v0.33.2

func (ss *PrimarySession) To() string

type RawSession

type RawSession struct {
	// contains filtered or unexported fields
}

The RawSession provides no authentication of senders, and there is no sender address attached to datagrams, so all communication is anonymous. The messages send are however still endpoint-to-endpoint encrypted. You need to figure out a way to identify and authenticate clients yourself, iff that is needed. Raw datagrams may be at most 32 kB in size. There is no overhead of authentication, which is the reason to use this..

func (*RawSession) Close

func (s *RawSession) Close() error

Closes the RawSession.

func (*RawSession) LocalAddr

func (s *RawSession) LocalAddr() i2pkeys.I2PAddr

Returns the local I2P destination of the RawSession.

func (*RawSession) Read

func (s *RawSession) Read(b []byte) (n int, err error)

Reads one raw datagram sent to the destination of the DatagramSession. Returns the number of bytes read. Who sent the raw message can not be determined at this layer - you need to do it (in a secure way!).

func (*RawSession) SetDeadline

func (s *RawSession) SetDeadline(t time.Time) error

func (*RawSession) SetReadDeadline

func (s *RawSession) SetReadDeadline(t time.Time) error

func (*RawSession) SetWriteDeadline

func (s *RawSession) SetWriteDeadline(t time.Time) error

func (*RawSession) WriteTo

func (s *RawSession) WriteTo(b []byte, addr i2pkeys.I2PAddr) (n int, err error)

Sends one raw datagram to the destination specified. At the time of writing, maximum size is 32 kilobyte, but this may change in the future.

type SAM

type SAM struct {
	Config SAMEmit
	// contains filtered or unexported fields
}

Used for controlling I2Ps SAMv3.

func NewSAM

func NewSAM(address string) (*SAM, error)

Creates a new controller for the I2P routers SAM bridge.

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) NewDatagramSession

func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*DatagramSession, error)

Creates a new datagram session. udpPort is the UDP port SAM is listening on, and if you set it to zero, it will use SAMs standard UDP port.

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) NewPrimarySession added in v0.33.2

func (sam *SAM) NewPrimarySession(id string, keys i2pkeys.I2PKeys, options []string) (*PrimarySession, error)

Creates a new PrimarySession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*SAM) NewPrimarySessionWithSignature added in v0.33.2

func (sam *SAM) NewPrimarySessionWithSignature(id string, keys i2pkeys.I2PKeys, options []string, sigType string) (*PrimarySession, error)

Creates a new PrimarySession with the I2CP- and PRIMARYinglib options as specified. See the I2P documentation for a full list of options.

func (*SAM) NewRawSession

func (s *SAM) NewRawSession(id string, keys i2pkeys.I2PKeys, options []string, udpPort int) (*RawSession, error)

Creates a new raw session. udpPort is the UDP port SAM is listening on, and if you set it to zero, it will use SAMs standard UDP port.

func (*SAM) NewStreamSession

func (sam *SAM) NewStreamSession(id string, keys i2pkeys.I2PKeys, options []string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*SAM) NewStreamSessionWithSignature

func (sam *SAM) NewStreamSessionWithSignature(id string, keys i2pkeys.I2PKeys, options []string, sigType string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*SAM) NewStreamSessionWithSignatureAndPorts

func (sam *SAM) NewStreamSessionWithSignatureAndPorts(id, from, to string, keys i2pkeys.I2PKeys, options []string, sigType string) (*StreamSession, error)

Creates a new StreamSession with the I2CP- and streaminglib options as specified. See the I2P documentation for a full list of options.

func (*SAM) ReadKeys

func (sam *SAM) ReadKeys(r io.Reader) (err error)

read public/private keys from an io.Reader

type SAMConn

type SAMConn struct {
	// contains filtered or unexported fields
}

import (

. "github.com/eyedeekay/i2pkeys"

)

Implements net.Conn

func (*SAMConn) Close

func (sc *SAMConn) Close() error

Implements net.Conn

func (*SAMConn) LocalAddr

func (sc *SAMConn) LocalAddr() net.Addr

func (*SAMConn) Read

func (sc *SAMConn) Read(buf []byte) (int, error)

Implements net.Conn

func (*SAMConn) RemoteAddr

func (sc *SAMConn) RemoteAddr() net.Addr

func (*SAMConn) SetDeadline

func (sc *SAMConn) SetDeadline(t time.Time) error

Implements net.Conn

func (*SAMConn) SetReadDeadline

func (sc *SAMConn) SetReadDeadline(t time.Time) error

Implements net.Conn

func (*SAMConn) SetWriteDeadline

func (sc *SAMConn) SetWriteDeadline(t time.Time) error

Implements net.Conn

func (*SAMConn) Write

func (sc *SAMConn) Write(buf []byte) (int, error)

Implements net.Conn

type SAMEmit added in v0.32.32

type SAMEmit struct {
	I2PConfig
}

func NewEmit added in v0.32.32

func NewEmit(opts ...func(*SAMEmit) error) (*SAMEmit, error)

func (*SAMEmit) Accept added in v0.32.32

func (e *SAMEmit) Accept() string

func (*SAMEmit) AcceptBytes added in v0.32.32

func (e *SAMEmit) AcceptBytes() []byte

func (*SAMEmit) Connect added in v0.32.32

func (e *SAMEmit) Connect(dest string) string

func (*SAMEmit) ConnectBytes added in v0.32.32

func (e *SAMEmit) ConnectBytes(dest string) []byte

func (*SAMEmit) Create added in v0.32.32

func (e *SAMEmit) Create() string

func (*SAMEmit) CreateBytes added in v0.32.32

func (e *SAMEmit) CreateBytes() []byte

func (*SAMEmit) GenerateDestination added in v0.32.32

func (e *SAMEmit) GenerateDestination() string

func (*SAMEmit) GenerateDestinationBytes added in v0.32.32

func (e *SAMEmit) GenerateDestinationBytes() []byte

func (*SAMEmit) Hello added in v0.32.32

func (e *SAMEmit) Hello() string

func (*SAMEmit) HelloBytes added in v0.32.32

func (e *SAMEmit) HelloBytes() []byte

func (*SAMEmit) Lookup added in v0.32.32

func (e *SAMEmit) Lookup(name string) string

func (*SAMEmit) LookupBytes added in v0.32.32

func (e *SAMEmit) LookupBytes(name string) []byte

func (*SAMEmit) OptStr added in v0.32.32

func (e *SAMEmit) OptStr() 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 StreamListener

type StreamListener struct {
	// contains filtered or unexported fields
}
Example
// One server Accept()ing on a StreamListener, and one client that Dials
// through I2P to the server. Server writes "Hello world!" through a SAMConn
// (which implements net.Conn) and the client prints the message.

const samBridge = "127.0.0.1:7656"

sam, err := NewSAM(samBridge)
if err != nil {
	fmt.Println(err.Error())
	return
}
defer sam.Close()
keys, err := sam.NewKeys()
if err != nil {
	fmt.Println(err.Error())
	return
}

quit := make(chan bool)

// Client connecting to the server
go func(server i2pkeys.I2PAddr) {
	csam, err := NewSAM(samBridge)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer csam.Close()
	keys, err := csam.NewKeys()
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	cs, err := csam.NewStreamSession("client_example", keys, Options_Small)
	if err != nil {
		fmt.Println(err.Error())
		quit <- false
		return
	}
	conn, err := cs.DialI2P(server)
	if err != nil {
		fmt.Println(err.Error())
		quit <- false
		return
	}
	buf := make([]byte, 256)
	n, err := conn.Read(buf)
	if err != nil {
		fmt.Println(err.Error())
		quit <- false
		return
	}
	fmt.Println(string(buf[:n]))
	quit <- true
}(keys.Addr()) // end of client

ss, err := sam.NewStreamSession("server_example", keys, Options_Small)
if err != nil {
	fmt.Println(err.Error())
	return
}
l, err := ss.Listen()
if err != nil {
	fmt.Println(err.Error())
	return
}
conn, err := l.Accept()
if err != nil {
	fmt.Println(err.Error())
	return
}
conn.Write([]byte("Hello world!"))

<-quit // waits for client to die, for example only
Output:

Hello world!

func (*StreamListener) Accept

func (l *StreamListener) Accept() (net.Conn, error)

implements net.Listener

func (*StreamListener) AcceptI2P

func (l *StreamListener) AcceptI2P() (*SAMConn, error)

accept a new inbound connection

func (*StreamListener) Addr

func (l *StreamListener) Addr() net.Addr

get our address implements net.Listener

func (*StreamListener) Close

func (l *StreamListener) Close() error

implements net.Listener

func (*StreamListener) From

func (l *StreamListener) From() string

func (*StreamListener) To

func (l *StreamListener) To() string

type StreamSession

type StreamSession struct {
	Timeout  time.Duration
	Deadline time.Time
	// contains filtered or unexported fields
}

Represents a streaming session.

Example
// Creates a new StreamingSession, dials to idk.i2p and gets a SAMConn
// which behaves just like a normal net.Conn.

const samBridge = "127.0.0.1:7656"

sam, err := NewSAM(samBridge)
if err != nil {
	fmt.Println(err.Error())
	return
}
defer sam.Close()
keys, err := sam.NewKeys()
if err != nil {
	fmt.Println(err.Error())
	return
}
// See the example Option_* variables.
ss, err := sam.NewStreamSession("stream_example", keys, Options_Small)
if err != nil {
	fmt.Println(err.Error())
	return
}
someone, err := sam.Lookup("idk.i2p")
if err != nil {
	fmt.Println(err.Error())
	return
}

conn, err := ss.DialI2P(someone)
if err != nil {
	fmt.Println(err.Error())
	return
}
defer conn.Close()
fmt.Println("Sending HTTP GET /")
if _, err := conn.Write([]byte("GET /\n")); err != nil {
	fmt.Println(err.Error())
	return
}
buf := make([]byte, 4096)
n, err := conn.Read(buf)
if !strings.Contains(strings.ToLower(string(buf[:n])), "http") && !strings.Contains(strings.ToLower(string(buf[:n])), "html") {
	fmt.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
	log.Printf("Probably failed to StreamSession.DialI2P(idk.i2p)? It replied %d bytes, but nothing that looked like http/html", n)
} else {
	fmt.Println("Read HTTP/HTML from idk.i2p")
	log.Println("Read HTTP/HTML from idk.i2p")
}
return
Output:

Sending HTTP GET /
Read HTTP/HTML from idk.i2p

func (*StreamSession) Addr

func (ss *StreamSession) Addr() i2pkeys.I2PAddr

Returns the I2P destination (the address) of the stream session

func (*StreamSession) Close

func (ss *StreamSession) Close() error

func (*StreamSession) Dial

func (s *StreamSession) Dial(n, addr string) (c net.Conn, err error)

implement net.Dialer

func (*StreamSession) DialContext

func (s *StreamSession) DialContext(ctx context.Context, n, addr string) (net.Conn, error)

context-aware dialer, eventually...

func (*StreamSession) DialContextI2P

func (s *StreamSession) DialContextI2P(ctx context.Context, n, addr string) (*SAMConn, error)

context-aware dialer, eventually...

func (*StreamSession) DialI2P

func (s *StreamSession) DialI2P(addr i2pkeys.I2PAddr) (*SAMConn, error)

Dials to an I2P destination and returns a SAMConn, which implements a net.Conn.

func (*StreamSession) From

func (ss *StreamSession) From() string

func (*StreamSession) ID

func (ss *StreamSession) ID() string

Returns the local tunnel name of the I2P tunnel used for the stream session

func (*StreamSession) Keys

func (ss *StreamSession) Keys() i2pkeys.I2PKeys

Returns the keys associated with the stream session

func (*StreamSession) Listen

func (s *StreamSession) Listen() (*StreamListener, error)

create a new stream listener to accept inbound connections

func (*StreamSession) LocalAddr added in v0.33.2

func (ss *StreamSession) LocalAddr() net.Addr

func (*StreamSession) Lookup

func (s *StreamSession) Lookup(name string) (i2pkeys.I2PAddr, error)

lookup name, convenience function

func (*StreamSession) SetDeadline added in v0.33.2

func (s *StreamSession) SetDeadline(t time.Time) error

func (*StreamSession) SetReadDeadline added in v0.33.2

func (s *StreamSession) SetReadDeadline(t time.Time) error

func (*StreamSession) SetWriteDeadline added in v0.33.2

func (s *StreamSession) SetWriteDeadline(t time.Time) error

func (*StreamSession) SignatureType

func (ss *StreamSession) SignatureType() string

func (*StreamSession) To

func (ss *StreamSession) To() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL