mirror of
https://github.com/go-i2p/goSam.git
synced 2025-06-11 02:08:38 -04:00
40 lines
625 B
Go
40 lines
625 B
Go
package goSam
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
// Implements the net.Dial function can be used for http.Transport
|
|
func (c *Client) Dial(network, addr string) (net.Conn, error) {
|
|
portIdx := strings.Index(addr, ":")
|
|
if portIdx >= 0 {
|
|
addr = addr[:portIdx]
|
|
}
|
|
addr, err := c.Lookup(addr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
id, _, err := c.CreateStreamSession("")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
newC, err := NewDefaultClient()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if c.verbose {
|
|
newC.ToggleVerbose()
|
|
}
|
|
|
|
err = newC.StreamConnect(id, addr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return newC.SamConn, nil
|
|
}
|