mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 14:18:25 -04:00
tidy up some things, add a destination parameter
This commit is contained in:
9
dial.go
9
dial.go
@ -31,13 +31,11 @@ func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) dialCheck(addr string) (int32, bool) {
|
func (c Client) dialCheck(addr string) (int32, bool) {
|
||||||
fmt.Println("DIAL CHECK")
|
|
||||||
if c.lastaddr == "invalid" {
|
if c.lastaddr == "invalid" {
|
||||||
fmt.Println("Preparing to dial new address.")
|
fmt.Println("Preparing to dial new address.")
|
||||||
return c.NewID(), true
|
return c.NewID(), true
|
||||||
}
|
}
|
||||||
fmt.Println("No new address to dial.")
|
return c.id, false
|
||||||
return c.NewID(), false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dial implements the net.Dial function and can be used for http.Transport
|
// Dial implements the net.Dial function and can be used for http.Transport
|
||||||
@ -51,10 +49,9 @@ func (c *Client) Dial(network, addr string) (net.Conn, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var id int32
|
|
||||||
var test bool
|
var test bool
|
||||||
if id, test = c.dialCheck(addr); test == true {
|
if c.id, test = c.dialCheck(addr); test == true {
|
||||||
c.destination, err = c.CreateStreamSession(id, "")
|
c.destination, err = c.CreateStreamSession(c.id, c.destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,15 @@ func SetHost(s string) func(*Client) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SetLocalDestination sets the local destination of the tunnel from a private
|
||||||
|
//key
|
||||||
|
func SetLocalDestination(s string) func(*Client) error {
|
||||||
|
return func(c *Client) error {
|
||||||
|
c.destination = s
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setlastaddr(s string) func(*Client) error {
|
func setlastaddr(s string) func(*Client) error {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
c.lastaddr = s
|
c.lastaddr = s
|
||||||
|
Reference in New Issue
Block a user