mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-06-15 21:28:46 -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/...
|
||||
|
||||
test-logs:
|
||||
make common-test 2> common-err.log 1> common-out.log
|
||||
make stream-test 2> stream-err.log 1> stream-out.log
|
||||
make datagram-test 2> datagram-err.log 1> datagram-out.log
|
||||
make raw-test 2> raw-err.log 1> raw-out.log
|
||||
make primary-test 2> primary-err.log 1> primary-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; cat stream-err.log stream-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; cat raw-err.log raw-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 {
|
||||
return func(c *SAMEmit) error {
|
||||
if len(s) > 0 {
|
||||
for _, a := range s {
|
||||
c.I2PConfig.AccessList = append(c.I2PConfig.AccessList, a)
|
||||
}
|
||||
c.I2PConfig.AccessList = append(c.I2PConfig.AccessList, s...)
|
||||
log.WithField("accessList", s).Debug("Set access list")
|
||||
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) {
|
||||
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
|
||||
sam.I2PConfig.Fromport = from
|
||||
sam.I2PConfig.Toport = to
|
||||
// Configure SAMEmit with all session parameters for message generation
|
||||
sam.SAMEmit.I2PConfig.Style = style
|
||||
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, " ")
|
||||
if extraStr != "" {
|
||||
baseMsg += " " + extraStr
|
||||
}
|
||||
|
||||
conn := sam.Conn
|
||||
fp := ""
|
||||
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")
|
||||
// Create final message with proper line termination
|
||||
scmsg := []byte(baseMsg + "\n")
|
||||
|
||||
log.WithField("message", string(scmsg)).Debug("Sending SESSION CREATE message")
|
||||
|
||||
conn := sam.Conn
|
||||
n, err := conn.Write(scmsg)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to write to SAM connection")
|
||||
|
Reference in New Issue
Block a user