goSam

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: GPL-2.0 Imports: 10 Imported by: 3

README

goSam

A go library for using the I2P Simple Anonymous Messaging (SAM version 3.0) bridge

This is in an early development stage. I would love to hear about any issues or ideas for improvement.

Installation

go get github.com/cryptix/goSam

Using it for HTTP Transport

I implemented Client.Dial like net.Dial so you can use go's library packages like http.

package main

import (
	"io"
	"log"
	"net/http"
	"os"

	"github.com/cryptix/goSam"
)

func main() {
	// create a default sam client
	sam, err := goSam.NewDefaultClient()
	checkErr(err)

	log.Println("Client Created")

	// create a transport that uses SAM to dial TCP Connections
	tr := &http.Transport{
		Dial: sam.Dial,
	}

	// create  a client using this transport
	client := &http.Client{Transport: tr}

	// send a get request
	resp, err := client.Get("http://stats.i2p/")
	checkErr(err)
	defer resp.Body.Close()

	log.Printf("Get returned %+v\n", resp)

	// create a file for the response
	file, err := os.Create("stats.html")
	checkErr(err)
	defer file.Close()

	// copy the response to the file
	_, err = io.Copy(file, resp.Body)
	checkErr(err)

	log.Println("Done.")
}

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}
TODO
  • Implement STREAM ACCEPT and STREAM FORWARD
  • Implement datagrams (Repliable and Anon)

Documentation

Index

Examples

Constants

View Source
const (
	ResultOk             = "OK"              //Operation completed successfully
	ResultCantReachPeer  = "CANT_REACH_PEER" //The peer exists, but cannot be reached
	ResultDuplicatedID   = "DUPLICATED_ID"   //If the nickname is already associated with a session :
	ResultDuplicatedDest = "DUPLICATED_DEST" //The specified Destination is already in use
	ResultI2PError       = "I2P_ERROR"       //A generic I2P error (e.g. I2CP disconnection, etc.)
	ResultInvalidKey     = "INVALID_KEY"     //The specified key is not valid (bad format, etc.)
	ResultKeyNotFound    = "KEY_NOT_FOUND"   //The naming system can't resolve the given name
	ResultPeerNotFound   = "PEER_NOT_FOUND"  //The peer cannot be found on the network
	ResultTimeout        = "TIMEOUT"         // Timeout while waiting for an event (e.g. peer answer)
)

The Possible Results send by SAM

Variables

This section is empty.

Functions

func SetAddr

func SetAddr(s ...string) func(*Client) error

SetAddr sets a clients's address in the form host:port or host, port

func SetAddrMixed

func SetAddrMixed(s string, i int) func(*Client) error

SetAddrMixed sets a clients's address in the form host, port(int)

func SetCloseIdle

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

SetCloseIdle tells the router to use an encrypted leaseset

func SetCloseIdleTime

func SetCloseIdleTime(u uint) func(*Client) error

SetCloseIdleTime sets the inbound tunnel backups

func SetDebug

func SetDebug(b bool) func(*Client) error

SetDebug enables debugging messages

func SetEncrypt

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

SetEncrypt tells the router to use an encrypted leaseset

func SetHost

func SetHost(s string) func(*Client) error

SetHost sets the host of the client's SAM bridge

func SetInBackups

func SetInBackups(u uint) func(*Client) error

SetInBackups sets the inbound tunnel backups

func SetInLength

func SetInLength(u uint) func(*Client) error

SetInLength sets the number of hops inbound

func SetInQuantity

func SetInQuantity(u uint) func(*Client) error

SetInQuantity sets the inbound tunnel quantity

func SetInVariance

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

SetInVariance sets the variance of a number of hops inbound

func SetOutBackups

func SetOutBackups(u uint) func(*Client) error

SetOutBackups sets the inbound tunnel backups

func SetOutLength

func SetOutLength(u uint) func(*Client) error

SetOutLength sets the number of hops outbound

func SetOutQuantity

func SetOutQuantity(u uint) func(*Client) error

SetOutQuantity sets the outbound tunnel quantity

func SetOutVariance

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

SetOutVariance sets the variance of a number of hops outbound

func SetPort

func SetPort(s string) func(*Client) error

SetPort sets the port of the client's SAM bridge using a string

func SetPortInt

func SetPortInt(i int) func(*Client) error

SetPortInt sets the port of the client's SAM bridge using a string

func SetReduceIdle

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

SetReduceIdle tells the router to use an encrypted leaseset

func SetReduceIdleQuantity

func SetReduceIdleQuantity(u uint) func(*Client) error

SetReduceIdleQuantity sets the inbound tunnel backups

func SetReduceIdleTime

func SetReduceIdleTime(u uint) func(*Client) error

SetReduceIdleTime sets the inbound tunnel backups

func SetUnpublished

func SetUnpublished(b bool) func(*Client) error

SetUnpublished tells the router to not publish the client leaseset

Types

type Client

type Client struct {
	SamConn net.Conn
	// contains filtered or unexported fields
}

A Client represents a single Connection to the SAM bridge

func NewClient

func NewClient(addr string) (*Client, error)

NewClient creates a new client, connecting to a specified port

func NewClientFromOptions

func NewClientFromOptions(opts ...func(*Client) error) (*Client, error)

NewClientFromOptions creates a new client, connecting to a specified port

func NewDefaultClient

func NewDefaultClient() (*Client, error)

NewDefaultClient creates a new client, connecting to the default host:port at localhost:7656

func (*Client) Accept

func (c *Client) Accept() (net.Conn, error)

Accept creates a new Client and accepts a connection on it

func (*Client) Close

func (c *Client) Close() error

Close the underlying socket to SAM

func (*Client) CreateStreamSession

func (c *Client) CreateStreamSession(dest string) (int32, string, error)

CreateStreamSession creates a new STREAM Session. Returns the Id for the new Client.

func (*Client) Dial

func (c *Client) Dial(network, addr string) (net.Conn, error)

Dial implements the net.Dial function and can be used for http.Transport

func (*Client) Lookup

func (c *Client) Lookup(name string) (string, error)

Lookup askes SAM for the internal i2p address from name

Example
client, err := NewDefaultClient()
if err != nil {
	fmt.Printf("NewDefaultClient() should not throw an error.\n%s\n", err)
	return
}

addr, err := client.Lookup("zzz.i2p")
if err != nil {
	fmt.Printf("client.Lookup() should not throw an error.\n%s\n", err)
	return
}

fmt.Println("Address of zzz.i2p:")
// Addresses change all the time
fmt.Println(addr)
Output:

Address of zzz.i2p:
GKapJ8koUcBj~jmQzHsTYxDg2tpfWj0xjQTzd8BhfC9c3OS5fwPBNajgF-eOD6eCjFTqTlorlh7Hnd8kXj1qblUGXT-tDoR9~YV8dmXl51cJn9MVTRrEqRWSJVXbUUz9t5Po6Xa247Vr0sJn27R4KoKP8QVj1GuH6dB3b6wTPbOamC3dkO18vkQkfZWUdRMDXk0d8AdjB0E0864nOT~J9Fpnd2pQE5uoFT6P0DqtQR2jsFvf9ME61aqLvKPPWpkgdn4z6Zkm-NJOcDz2Nv8Si7hli94E9SghMYRsdjU-knObKvxiagn84FIwcOpepxuG~kFXdD5NfsH0v6Uri3usE3uSzpWS0EHmrlfoLr5uGGd9ZHwwCIcgfOATaPRMUEQxiK9q48PS0V3EXXO4-YLT0vIfk4xO~XqZpn8~PW1kFe2mQMHd7oO89yCk-3yizRG3UyFtI7-mO~eCI6-m1spYoigStgoupnC3G85gJkqEjMm49gUjbhfWKWI-6NwTj0ZnAAAA

func (*Client) StreamAccept

func (c *Client) StreamAccept(id int32) (*Reply, error)

StreamAccept asks SAM to accept a TCP-Like connection

func (*Client) StreamConnect

func (c *Client) StreamConnect(id int32, dest string) error

StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client

type Option

type Option func(*Client) error

Option is a client Option

type Reply

type Reply struct {
	Topic string
	Type  string

	Pairs map[string]string
}

Reply is the parsed result of a SAM command, containing a map of all the key-value pairs

type ReplyError

type ReplyError struct {
	Result string
	Reply  *Reply
}

A ReplyError is a custom error type, containing the Result and full Reply

func (ReplyError) Error

func (r ReplyError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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