mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-19 10:35:42 -04:00
simplify NewGenericSessionWithSignatureAndPorts
This commit is contained in:
10
Makefile
10
Makefile
@@ -19,8 +19,8 @@ raw-test:
|
|||||||
go test --tags nettest -v ./raw/...
|
go test --tags nettest -v ./raw/...
|
||||||
|
|
||||||
test-logs:
|
test-logs:
|
||||||
make common-test 2> common-err.log 1> common-out.log
|
make common-test 2> common-err.log 1> common-out.log; cat common-err.log common-out.log
|
||||||
make stream-test 2> stream-err.log 1> stream-out.log
|
make stream-test 2> stream-err.log 1> stream-out.log; cat stream-err.log stream-out.log
|
||||||
make datagram-test 2> datagram-err.log 1> datagram-out.log
|
#make datagram-test 2> datagram-err.log 1> datagram-out.log; cat datagram-err.log datagram-out.log
|
||||||
make raw-test 2> raw-err.log 1> raw-out.log
|
#make raw-test 2> raw-err.log 1> raw-out.log; cat raw-err.log raw-out.log
|
||||||
make primary-test 2> primary-err.log 1> primary-out.log
|
#make primary-test 2> primary-err.log 1> primary-out.log; cat primary-err.log primary-out.log
|
||||||
|
@@ -414,9 +414,7 @@ func SetAccessListType(s string) func(*SAMEmit) error {
|
|||||||
func SetAccessList(s []string) func(*SAMEmit) error {
|
func SetAccessList(s []string) func(*SAMEmit) error {
|
||||||
return func(c *SAMEmit) error {
|
return func(c *SAMEmit) error {
|
||||||
if len(s) > 0 {
|
if len(s) > 0 {
|
||||||
for _, a := range s {
|
c.I2PConfig.AccessList = append(c.I2PConfig.AccessList, s...)
|
||||||
c.I2PConfig.AccessList = append(c.I2PConfig.AccessList, a)
|
|
||||||
}
|
|
||||||
log.WithField("accessList", s).Debug("Set access list")
|
log.WithField("accessList", s).Debug("Set access list")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -31,26 +31,29 @@ func (sam SAM) NewGenericSessionWithSignature(style, id string, keys i2pkeys.I2P
|
|||||||
func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error) {
|
func (sam SAM) NewGenericSessionWithSignatureAndPorts(style, id, from, to string, keys i2pkeys.I2PKeys, sigType string, extras []string) (Session, error) {
|
||||||
log.WithFields(logrus.Fields{"style": style, "id": id, "from": from, "to": to, "sigType": sigType}).Debug("Creating new generic session with signature and ports")
|
log.WithFields(logrus.Fields{"style": style, "id": id, "from": from, "to": to, "sigType": sigType}).Debug("Creating new generic session with signature and ports")
|
||||||
|
|
||||||
// Update SAM configuration with session-specific ports
|
// Configure SAMEmit with all session parameters for message generation
|
||||||
sam.I2PConfig.Fromport = from
|
sam.SAMEmit.I2PConfig.Style = style
|
||||||
sam.I2PConfig.Toport = to
|
sam.SAMEmit.I2PConfig.TunName = id
|
||||||
|
sam.SAMEmit.I2PConfig.DestinationKeys = &keys
|
||||||
|
sam.SAMEmit.I2PConfig.SigType = sigType
|
||||||
|
sam.SAMEmit.I2PConfig.Fromport = from
|
||||||
|
sam.SAMEmit.I2PConfig.Toport = to
|
||||||
|
|
||||||
optStr := sam.SamOptionsString()
|
// Generate the base SESSION CREATE message using emitter
|
||||||
|
baseMsg := strings.TrimSuffix(sam.SAMEmit.Create(), " \n")
|
||||||
|
|
||||||
|
// Append any extra parameters if provided
|
||||||
extraStr := strings.Join(extras, " ")
|
extraStr := strings.Join(extras, " ")
|
||||||
|
if extraStr != "" {
|
||||||
|
baseMsg += " " + extraStr
|
||||||
|
}
|
||||||
|
|
||||||
conn := sam.Conn
|
// Create final message with proper line termination
|
||||||
fp := ""
|
scmsg := []byte(baseMsg + "\n")
|
||||||
tp := ""
|
|
||||||
if from != "0" {
|
|
||||||
fp = " FROM_PORT=" + from
|
|
||||||
}
|
|
||||||
if to != "0" {
|
|
||||||
tp = " TO_PORT=" + to
|
|
||||||
}
|
|
||||||
scmsg := []byte("SESSION CREATE STYLE=" + style + fp + tp + " ID=" + id + " DESTINATION=" + keys.String() + " " + optStr + " " + extraStr + "\n")
|
|
||||||
|
|
||||||
log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message")
|
log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message")
|
||||||
|
|
||||||
|
conn := sam.Conn
|
||||||
n, err := conn.Write(scmsg)
|
n, err := conn.Write(scmsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("Failed to write to SAM connection")
|
log.WithError(err).Error("Failed to write to SAM connection")
|
||||||
|
Reference in New Issue
Block a user