make it easy to get the addresses of the gosam tunnels
This commit is contained in:
33
client.go
33
client.go
@ -2,10 +2,15 @@ package goSam
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha256"
|
||||
"encoding/base32"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/eyedeekay/gosam/debug"
|
||||
)
|
||||
@ -57,6 +62,11 @@ var SAMsigTypes = []string{
|
||||
"SIGNATURE_TYPE=EdDSA_SHA512_Ed25519",
|
||||
}
|
||||
|
||||
var (
|
||||
i2pB64enc *base64.Encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~")
|
||||
i2pB32enc *base32.Encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
|
||||
)
|
||||
|
||||
// NewDefaultClient creates a new client, connecting to the default host:port at localhost:7656
|
||||
func NewDefaultClient() (*Client, error) {
|
||||
return NewClient("localhost:7656")
|
||||
@ -72,6 +82,29 @@ func (c *Client) NewID() int32 {
|
||||
return rand.Int31n(math.MaxInt32)
|
||||
}
|
||||
|
||||
// Destination returns the full destination of the local tunnel
|
||||
func (c *Client) Destination() string {
|
||||
return c.destination
|
||||
}
|
||||
|
||||
// Base32 returns the base32 of the local tunnel
|
||||
func (c *Client) Base32() string {
|
||||
hash := sha256.New()
|
||||
hash.Write([]byte(c.base64()))
|
||||
return strings.ToLower(strings.Replace(i2pB32enc.EncodeToString(hash.Sum(nil)), "=", "", -1))
|
||||
}
|
||||
|
||||
func (c *Client) base64() []byte {
|
||||
s, _ := i2pB64enc.DecodeString(c.destination)
|
||||
alen := binary.BigEndian.Uint16(s[385:387])
|
||||
return s[:387+alen]
|
||||
}
|
||||
|
||||
// Base64 returns the base64 of the local tunnel
|
||||
func (c *Client) Base64() string {
|
||||
return i2pB64enc.EncodeToString(c.base64())
|
||||
}
|
||||
|
||||
// NewClientFromOptions creates a new client, connecting to a specified port
|
||||
func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
||||
var c Client
|
||||
|
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,3 +1,9 @@
|
||||
golang-github-eyedeekay-gosam (0.1.1) bionic; urgency=medium
|
||||
|
||||
* Incorporate all the recent bug-fixes and improvements and stabilize.
|
||||
|
||||
-- idk <hankhill19580@gmail.com> Fri, 15 Mar 2019 14:46:21 -0500
|
||||
|
||||
golang-github-eyedeekay-gosam (0.1.0+git20190221.2896c83ubuntu1+nmu2ubuntu1) bionic; urgency=medium
|
||||
|
||||
* only run the offline tests by default
|
||||
|
20
options.go
20
options.go
@ -417,3 +417,23 @@ func (c *Client) allOptions() string {
|
||||
c.closeidletime() +
|
||||
c.compresion()
|
||||
}
|
||||
|
||||
//Print return all options as string
|
||||
func (c *Client) Print() string {
|
||||
return c.inlength() +
|
||||
c.outlength() +
|
||||
c.invariance() +
|
||||
c.outvariance() +
|
||||
c.inquantity() +
|
||||
c.outquantity() +
|
||||
c.inbackups() +
|
||||
c.outbackups() +
|
||||
c.dontpublishlease() +
|
||||
c.encryptlease() +
|
||||
c.reduceonidle() +
|
||||
c.reduceidletime() +
|
||||
c.reduceidlecount() +
|
||||
c.closeonidle() +
|
||||
c.closeidletime() +
|
||||
c.compresion()
|
||||
}
|
||||
|
@ -45,10 +45,13 @@ func TestOptionAddrString(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
||||
func TestOptionAddrStringLh(t *testing.T) {
|
||||
@ -61,10 +64,13 @@ func TestOptionAddrStringLh(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
||||
func TestOptionAddrSlice(t *testing.T) {
|
||||
@ -77,10 +83,13 @@ func TestOptionAddrSlice(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
||||
func TestOptionAddrMixedSlice(t *testing.T) {
|
||||
@ -93,10 +102,13 @@ func TestOptionAddrMixedSlice(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
||||
func TestOptionHost(t *testing.T) {
|
||||
@ -128,10 +140,13 @@ func TestOptionHost(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
||||
func TestOptionPortInt(t *testing.T) {
|
||||
@ -163,8 +178,11 @@ func TestOptionPortInt(t *testing.T) {
|
||||
} else {
|
||||
t.Log(result)
|
||||
}
|
||||
client.CreateStreamSession(client.NewID(), "")
|
||||
dest, _ := client.CreateStreamSession(client.NewID(), "")
|
||||
if err := client.Close(); err != nil {
|
||||
t.Fatalf("client.Close() Error: %q\n", err)
|
||||
}
|
||||
fmt.Printf("\t destination- %s \n", dest)
|
||||
fmt.Printf("\t address64- %s \t", client.Base64())
|
||||
fmt.Printf("\t address- %s \t", client.Base32())
|
||||
}
|
||||
|
@ -38,6 +38,6 @@ func (c *Client) CreateStreamSession(id int32, dest string) (string, error) {
|
||||
if result != "OK" {
|
||||
return "", ReplyError{ResultKeyNotFound, r}
|
||||
}
|
||||
|
||||
return r.Pairs["DESTINATION"], nil
|
||||
c.destination = r.Pairs["DESTINATION"]
|
||||
return c.destination, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user