mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-06-07 09:03:18 -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) {
|
||||
//TODO: copy them?
|
||||
// TODO: copy them?
|
||||
log.Debug("Retrieving SAM keys")
|
||||
k = sam.SAMEmit.I2PConfig.DestinationKeys
|
||||
return
|
||||
@ -98,7 +98,7 @@ func (sam *SAM) EnsureKeyfile(fname string) (keys i2pkeys.I2PKeys, err error) {
|
||||
sam.SAMEmit.I2PConfig.DestinationKeys = &keys
|
||||
// save keys
|
||||
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 {
|
||||
err = i2pkeys.StoreKeysIncompat(keys, f)
|
||||
f.Close()
|
||||
|
@ -452,7 +452,7 @@ func (f *I2PConfig) LeaseSetEncryptionType() string {
|
||||
for _, s := range strings.Split(f.LeaseSetEncryption, ",") {
|
||||
if _, err := strconv.Atoi(s); err != nil {
|
||||
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
|
||||
|
||||
const DEFAULT_SAM_MIN = "3.1"
|
||||
const DEFAULT_SAM_MAX = "3.3"
|
||||
const (
|
||||
DEFAULT_SAM_MIN = "3.1"
|
||||
DEFAULT_SAM_MAX = "3.3"
|
||||
)
|
||||
|
||||
const (
|
||||
SESSION_OK = "SESSION STATUS RESULT=OK DESTINATION="
|
||||
|
@ -45,13 +45,13 @@ func (e *SAMEmit) Create() string {
|
||||
create := fmt.Sprintf(
|
||||
// //1 2 3 4 5 6 7
|
||||
"SESSION CREATE %s%s%s%s%s%s%s \n",
|
||||
e.I2PConfig.SessionStyle(), //1
|
||||
e.I2PConfig.FromPort(), //2
|
||||
e.I2PConfig.ToPort(), //3
|
||||
e.I2PConfig.ID(), //4
|
||||
e.I2PConfig.DestinationKey(), //5
|
||||
e.I2PConfig.SignatureType(), //6
|
||||
e.SamOptionsString(), //7
|
||||
e.I2PConfig.SessionStyle(), // 1
|
||||
e.I2PConfig.FromPort(), // 2
|
||||
e.I2PConfig.ToPort(), // 3
|
||||
e.I2PConfig.ID(), // 4
|
||||
e.I2PConfig.DestinationKey(), // 5
|
||||
e.I2PConfig.SignatureType(), // 6
|
||||
e.SamOptionsString(), // 7
|
||||
)
|
||||
log.WithField("create", create).Debug("Generated SESSION CREATE command")
|
||||
return create
|
||||
|
@ -56,7 +56,7 @@ func (sam *SAMResolver) Resolve(name string) (i2pkeys.I2PAddr, error) {
|
||||
for s.Scan() {
|
||||
text := s.Text()
|
||||
log.WithField("text", text).Debug("Parsing SAM response token")
|
||||
//log.Println("SAM3", text)
|
||||
// log.Println("SAM3", text)
|
||||
if text == SAM_RESULT_OK {
|
||||
continue
|
||||
} else if text == SAM_RESULT_INVALID_KEY {
|
||||
|
@ -50,7 +50,7 @@ type I2PConfig struct {
|
||||
ReduceIdleQuantity int
|
||||
LeaseSetEncryption string
|
||||
|
||||
//Streaming Library options
|
||||
// Streaming Library options
|
||||
AccessListType string
|
||||
AccessList []string
|
||||
}
|
||||
|
@ -74,5 +74,5 @@ func (s *SAM) NewDatagramSession(id string, keys i2pkeys.I2PKeys, options []stri
|
||||
}
|
||||
datagramSession.Conn = conn
|
||||
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
|
||||
}
|
||||
|
||||
func (s *DatagramSession) Dial(net string, addr string) (*DatagramSession, error) {
|
||||
func (s *DatagramSession) Dial(net, addr string) (*DatagramSession, error) {
|
||||
log.WithFields(logrus.Fields{
|
||||
"net": net,
|
||||
"addr": addr,
|
||||
|
@ -13,11 +13,11 @@ import (
|
||||
func (sam *PrimarySession) Dial(network, addr string) (net.Conn, error) {
|
||||
log.WithFields(logrus.Fields{"network": network, "addr": addr}).Debug("Dial() called")
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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())
|
||||
}
|
||||
|
||||
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")
|
||||
ts, ok := sam.stsess[network+raddr[0:4]]
|
||||
var err error
|
||||
|
@ -69,7 +69,7 @@ func (sam *PrimarySession) NewGenericSubSessionWithSignatureAndPorts(style, id,
|
||||
}
|
||||
text := string(buf[:n])
|
||||
log.WithField("response", text).Debug("Received response from SAM")
|
||||
//log.Println("SAM:", text)
|
||||
// log.Println("SAM:", text)
|
||||
if strings.HasPrefix(text, SESSION_ADDOK) {
|
||||
//if sam.keys.String() != text[len(common.SESSION_ADDOK):len(text)-1] {
|
||||
//conn.Close()
|
||||
|
@ -52,7 +52,7 @@ func (s *StreamSession) Dial(n, addr string) (c net.Conn, err error) {
|
||||
var i2paddr i2pkeys.I2PAddr
|
||||
var host string
|
||||
host, _, err = net.SplitHostPort(addr)
|
||||
//log.Println("Dialing:", host)
|
||||
// log.Println("Dialing:", host)
|
||||
if err = common.IgnorePortError(err); err == nil {
|
||||
// check for name
|
||||
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 {
|
||||
// probably a destination
|
||||
i2paddr, err = i2pkeys.NewI2PAddrFromBytes([]byte(host))
|
||||
//i2paddr = i2pkeys.I2PAddr(host)
|
||||
//log.Println("Destination:", i2paddr, err)
|
||||
// i2paddr = i2pkeys.I2PAddr(host)
|
||||
// log.Println("Destination:", i2paddr, err)
|
||||
log.WithFields(logrus.Fields{"host": host, "i2paddr": i2paddr}).Debug("Created I2P address from bytes")
|
||||
}
|
||||
if err == nil {
|
||||
|
Reference in New Issue
Block a user