mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 14:18:25 -04:00
Allow clients to force a handshake at a specific SAM version or between SAM versions
This commit is contained in:
16
client.go
16
client.go
@ -11,7 +11,7 @@ import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
// "sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -53,10 +53,9 @@ type Client struct {
|
||||
|
||||
debug bool
|
||||
//NEVER, EVER modify lastaddr or id yourself. They are used internally only.
|
||||
lastaddr string
|
||||
id int32
|
||||
ml sync.Mutex
|
||||
oml sync.Mutex
|
||||
id int32
|
||||
sammin int
|
||||
sammax int
|
||||
}
|
||||
|
||||
var SAMsigTypes = []string{
|
||||
@ -153,18 +152,19 @@ func NewClientFromOptions(opts ...func(*Client) error) (*Client, error) {
|
||||
c.debug = false
|
||||
c.sigType = SAMsigTypes[4]
|
||||
c.id = 0
|
||||
c.lastaddr = "invalid"
|
||||
c.destination = ""
|
||||
c.leaseSetEncType = "4,0"
|
||||
c.fromport = ""
|
||||
c.toport = ""
|
||||
c.sammin = 0
|
||||
c.sammax = 1
|
||||
for _, o := range opts {
|
||||
if err := o(&c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.id = c.NewID()
|
||||
conn, err := net.DialTimeout("tcp", c.samaddr(), 3*time.Minute)
|
||||
conn, err := net.DialTimeout("tcp", c.samaddr(), 15*time.Minute)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (c *Client) samaddr() string {
|
||||
|
||||
// send the initial handshake command and check that the reply is ok
|
||||
func (c *Client) hello() error {
|
||||
r, err := c.sendCmd("HELLO VERSION MIN=3.0 MAX=3.2\n")
|
||||
r, err := c.sendCmd("HELLO VERSION MIN=3.%d MAX=3.%d\n", c.sammin, c.sammax)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user