mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-06-07 17:05:04 -04:00
piece out sam3
This commit is contained in:
@ -57,7 +57,7 @@ func OldNewSAM(address string) (*SAM, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sam *SAM) Keys() (k *i2pkeys.I2PKeys) {
|
func (sam *SAM) Keys() (k *i2pkeys.I2PKeys) {
|
||||||
//TODO: copy them?
|
// TODO: copy them?
|
||||||
log.Debug("Retrieving SAM keys")
|
log.Debug("Retrieving SAM keys")
|
||||||
k = sam.SAMEmit.I2PConfig.DestinationKeys
|
k = sam.SAMEmit.I2PConfig.DestinationKeys
|
||||||
return
|
return
|
||||||
@ -98,7 +98,7 @@ func (sam *SAM) EnsureKeyfile(fname string) (keys i2pkeys.I2PKeys, err error) {
|
|||||||
sam.SAMEmit.I2PConfig.DestinationKeys = &keys
|
sam.SAMEmit.I2PConfig.DestinationKeys = &keys
|
||||||
// save keys
|
// save keys
|
||||||
var f io.WriteCloser
|
var f io.WriteCloser
|
||||||
f, err = os.OpenFile(fname, os.O_WRONLY|os.O_CREATE, 0600)
|
f, err = os.OpenFile(fname, os.O_WRONLY|os.O_CREATE, 0o600)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = i2pkeys.StoreKeysIncompat(keys, f)
|
err = i2pkeys.StoreKeysIncompat(keys, f)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
@ -452,7 +452,7 @@ func (f *I2PConfig) LeaseSetEncryptionType() string {
|
|||||||
for _, s := range strings.Split(f.LeaseSetEncryption, ",") {
|
for _, s := range strings.Split(f.LeaseSetEncryption, ",") {
|
||||||
if _, err := strconv.Atoi(s); err != nil {
|
if _, err := strconv.Atoi(s); err != nil {
|
||||||
log.WithField("invalidType", s).Panic("Invalid encrypted leaseSet type")
|
log.WithField("invalidType", s).Panic("Invalid encrypted leaseSet type")
|
||||||
//panic("Invalid encrypted leaseSet type: " + s)
|
// panic("Invalid encrypted leaseSet type: " + s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
const DEFAULT_SAM_MIN = "3.1"
|
const (
|
||||||
const DEFAULT_SAM_MAX = "3.3"
|
DEFAULT_SAM_MIN = "3.1"
|
||||||
|
DEFAULT_SAM_MAX = "3.3"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SESSION_OK = "SESSION STATUS RESULT=OK DESTINATION="
|
SESSION_OK = "SESSION STATUS RESULT=OK DESTINATION="
|
||||||
|
@ -45,13 +45,13 @@ func (e *SAMEmit) Create() string {
|
|||||||
create := fmt.Sprintf(
|
create := fmt.Sprintf(
|
||||||
// //1 2 3 4 5 6 7
|
// //1 2 3 4 5 6 7
|
||||||
"SESSION CREATE %s%s%s%s%s%s%s \n",
|
"SESSION CREATE %s%s%s%s%s%s%s \n",
|
||||||
e.I2PConfig.SessionStyle(), //1
|
e.I2PConfig.SessionStyle(), // 1
|
||||||
e.I2PConfig.FromPort(), //2
|
e.I2PConfig.FromPort(), // 2
|
||||||
e.I2PConfig.ToPort(), //3
|
e.I2PConfig.ToPort(), // 3
|
||||||
e.I2PConfig.ID(), //4
|
e.I2PConfig.ID(), // 4
|
||||||
e.I2PConfig.DestinationKey(), //5
|
e.I2PConfig.DestinationKey(), // 5
|
||||||
e.I2PConfig.SignatureType(), //6
|
e.I2PConfig.SignatureType(), // 6
|
||||||
e.SamOptionsString(), //7
|
e.SamOptionsString(), // 7
|
||||||
)
|
)
|
||||||
log.WithField("create", create).Debug("Generated SESSION CREATE command")
|
log.WithField("create", create).Debug("Generated SESSION CREATE command")
|
||||||
return create
|
return create
|
||||||
|
@ -56,7 +56,7 @@ func (sam *SAMResolver) Resolve(name string) (i2pkeys.I2PAddr, error) {
|
|||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
text := s.Text()
|
text := s.Text()
|
||||||
log.WithField("text", text).Debug("Parsing SAM response token")
|
log.WithField("text", text).Debug("Parsing SAM response token")
|
||||||
//log.Println("SAM3", text)
|
// log.Println("SAM3", text)
|
||||||
if text == SAM_RESULT_OK {
|
if text == SAM_RESULT_OK {
|
||||||
continue
|
continue
|
||||||
} else if text == SAM_RESULT_INVALID_KEY {
|
} else if text == SAM_RESULT_INVALID_KEY {
|
||||||
|
@ -50,7 +50,7 @@ type I2PConfig struct {
|
|||||||
ReduceIdleQuantity int
|
ReduceIdleQuantity int
|
||||||
LeaseSetEncryption string
|
LeaseSetEncryption string
|
||||||
|
|
||||||
//Streaming Library options
|
// Streaming Library options
|
||||||
AccessListType string
|
AccessListType string
|
||||||
AccessList []string
|
AccessList []string
|
||||||
}
|
}
|
||||||
|
@ -74,5 +74,5 @@ func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []stri
|
|||||||
}
|
}
|
||||||
datagramSession.Conn = conn
|
datagramSession.Conn = conn
|
||||||
return datagramSession, nil
|
return datagramSession, nil
|
||||||
//return &DatagramSession{s.address, id, conn, udpconn, keys, rUDPAddr, nil}, nil
|
// return &DatagramSession{s.address, id, conn, udpconn, keys, rUDPAddr, nil}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (s *DatagramSession) B32() string {
|
|||||||
return b32
|
return b32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DatagramSession) Dial(net string, addr string) (*DatagramSession, error) {
|
func (s *DatagramSession) Dial(net, addr string) (*DatagramSession, error) {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"net": net,
|
"net": net,
|
||||||
"addr": addr,
|
"addr": addr,
|
||||||
|
@ -13,11 +13,11 @@ import (
|
|||||||
func (sam *PrimarySession) Dial(network, addr string) (net.Conn, error) {
|
func (sam *PrimarySession) Dial(network, addr string) (net.Conn, error) {
|
||||||
log.WithFields(logrus.Fields{"network": network, "addr": addr}).Debug("Dial() called")
|
log.WithFields(logrus.Fields{"network": network, "addr": addr}).Debug("Dial() called")
|
||||||
if network == "udp" || network == "udp4" || network == "udp6" {
|
if network == "udp" || network == "udp4" || network == "udp6" {
|
||||||
//return sam.DialUDPI2P(network, network+addr[0:4], addr)
|
// return sam.DialUDPI2P(network, network+addr[0:4], addr)
|
||||||
return sam.DialUDPI2P(network, network+addr[0:4], addr)
|
return sam.DialUDPI2P(network, network+addr[0:4], addr)
|
||||||
}
|
}
|
||||||
if network == "tcp" || network == "tcp4" || network == "tcp6" {
|
if network == "tcp" || network == "tcp4" || network == "tcp6" {
|
||||||
//return sam.DialTCPI2P(network, network+addr[0:4], addr)
|
// return sam.DialTCPI2P(network, network+addr[0:4], addr)
|
||||||
return sam.DialTCPI2P(network, network+addr[0:4], addr)
|
return sam.DialTCPI2P(network, network+addr[0:4], addr)
|
||||||
}
|
}
|
||||||
log.WithField("network", network).Error("Invalid network type")
|
log.WithField("network", network).Error("Invalid network type")
|
||||||
@ -41,7 +41,7 @@ func (sam *PrimarySession) DialTCP(network string, laddr, raddr net.Addr) (net.C
|
|||||||
return ts.Dial(network, raddr.String())
|
return ts.Dial(network, raddr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sam *PrimarySession) DialTCPI2P(network string, laddr, raddr string) (net.Conn, error) {
|
func (sam *PrimarySession) DialTCPI2P(network, laddr, raddr string) (net.Conn, error) {
|
||||||
log.WithFields(logrus.Fields{"network": network, "laddr": laddr, "raddr": raddr}).Debug("DialTCPI2P() called")
|
log.WithFields(logrus.Fields{"network": network, "laddr": laddr, "raddr": raddr}).Debug("DialTCPI2P() called")
|
||||||
ts, ok := sam.stsess[network+raddr[0:4]]
|
ts, ok := sam.stsess[network+raddr[0:4]]
|
||||||
var err error
|
var err error
|
||||||
|
@ -69,7 +69,7 @@ func (sam *PrimarySession) NewGenericSubSessionWithSignatureAndPorts(style, id,
|
|||||||
}
|
}
|
||||||
text := string(buf[:n])
|
text := string(buf[:n])
|
||||||
log.WithField("response", text).Debug("Received response from SAM")
|
log.WithField("response", text).Debug("Received response from SAM")
|
||||||
//log.Println("SAM:", text)
|
// log.Println("SAM:", text)
|
||||||
if strings.HasPrefix(text, SESSION_ADDOK) {
|
if strings.HasPrefix(text, SESSION_ADDOK) {
|
||||||
//if sam.keys.String() != text[len(common.SESSION_ADDOK):len(text)-1] {
|
//if sam.keys.String() != text[len(common.SESSION_ADDOK):len(text)-1] {
|
||||||
//conn.Close()
|
//conn.Close()
|
||||||
|
@ -52,7 +52,7 @@ func (s *StreamSession) Dial(n, addr string) (c net.Conn, err error) {
|
|||||||
var i2paddr i2pkeys.I2PAddr
|
var i2paddr i2pkeys.I2PAddr
|
||||||
var host string
|
var host string
|
||||||
host, _, err = net.SplitHostPort(addr)
|
host, _, err = net.SplitHostPort(addr)
|
||||||
//log.Println("Dialing:", host)
|
// log.Println("Dialing:", host)
|
||||||
if err = common.IgnorePortError(err); err == nil {
|
if err = common.IgnorePortError(err); err == nil {
|
||||||
// check for name
|
// check for name
|
||||||
if strings.HasSuffix(host, ".b32.i2p") || strings.HasSuffix(host, ".i2p") {
|
if strings.HasSuffix(host, ".b32.i2p") || strings.HasSuffix(host, ".i2p") {
|
||||||
@ -62,8 +62,8 @@ func (s *StreamSession) Dial(n, addr string) (c net.Conn, err error) {
|
|||||||
} else {
|
} else {
|
||||||
// probably a destination
|
// probably a destination
|
||||||
i2paddr, err = i2pkeys.NewI2PAddrFromBytes([]byte(host))
|
i2paddr, err = i2pkeys.NewI2PAddrFromBytes([]byte(host))
|
||||||
//i2paddr = i2pkeys.I2PAddr(host)
|
// i2paddr = i2pkeys.I2PAddr(host)
|
||||||
//log.Println("Destination:", i2paddr, err)
|
// log.Println("Destination:", i2paddr, err)
|
||||||
log.WithFields(logrus.Fields{"host": host, "i2paddr": i2paddr}).Debug("Created I2P address from bytes")
|
log.WithFields(logrus.Fields{"host": host, "i2paddr": i2paddr}).Debug("Created I2P address from bytes")
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Reference in New Issue
Block a user