mirror of
https://github.com/go-i2p/goSam.git
synced 2025-06-09 17:34:18 -04:00
add ability to query tnnel id
This commit is contained in:
26
client.go
26
client.go
@ -2,25 +2,25 @@ package goSam
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"crypto/sha256"
|
||||
"encoding/base32"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
"strings"
|
||||
|
||||
"github.com/eyedeekay/gosam/debug"
|
||||
)
|
||||
|
||||
// A Client represents a single Connection to the SAM bridge
|
||||
type Client struct {
|
||||
host string
|
||||
port string
|
||||
fromport string
|
||||
toport string
|
||||
host string
|
||||
port string
|
||||
fromport string
|
||||
toport string
|
||||
|
||||
SamConn net.Conn
|
||||
rd *bufio.Reader
|
||||
@ -91,15 +91,15 @@ func (c *Client) Destination() string {
|
||||
|
||||
// Base32 returns the base32 of the local tunnel
|
||||
func (c *Client) Base32() string {
|
||||
hash := sha256.New()
|
||||
hash.Write([]byte(c.base64()))
|
||||
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]
|
||||
alen := binary.BigEndian.Uint16(s[385:387])
|
||||
return s[:387+alen]
|
||||
}
|
||||
|
||||
// Base64 returns the base64 of the local tunnel
|
||||
@ -149,6 +149,10 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
||||
return &c, c.hello()
|
||||
}
|
||||
|
||||
func (p *Client) ID() string {
|
||||
return fmt.Sprintf("%d", p.id)
|
||||
}
|
||||
|
||||
//return the combined host:port of the SAM bridge
|
||||
func (c *Client) samaddr() string {
|
||||
return fmt.Sprintf("%s:%s", c.host, c.port)
|
||||
|
@ -163,7 +163,6 @@ func SetToPortInt(i int) func(*Client) error {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//SetDebug enables debugging messages
|
||||
func SetDebug(b bool) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
@ -364,7 +363,6 @@ func (c *Client) from() string {
|
||||
return fmt.Sprintf(" FROM_PORT=%v ", c.fromport)
|
||||
}
|
||||
|
||||
|
||||
//return the to port as a string.
|
||||
func (c *Client) to() string {
|
||||
return fmt.Sprintf(" TO_PORT=%v ", c.toport)
|
||||
|
@ -21,8 +21,8 @@ func (c *Client) CreateStreamSession(id int32, dest string) (string, error) {
|
||||
r, err := c.sendCmd(
|
||||
"SESSION CREATE STYLE=STREAM ID=%d %s %s DESTINATION=%s %s %s\n",
|
||||
c.id,
|
||||
c.from(),
|
||||
c.to(),
|
||||
c.from(),
|
||||
c.to(),
|
||||
dest,
|
||||
c.sigtype(),
|
||||
c.allOptions(),
|
||||
|
Reference in New Issue
Block a user