summaryrefslogtreecommitdiffhomepage
path: root/server/sockopt.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/sockopt.go')
-rw-r--r--server/sockopt.go60
1 files changed, 54 insertions, 6 deletions
diff --git a/server/sockopt.go b/server/sockopt.go
index 2f6a8bb6..e053bef0 100644
--- a/server/sockopt.go
+++ b/server/sockopt.go
@@ -19,20 +19,68 @@ package server
import (
"fmt"
"net"
+
+ log "github.com/sirupsen/logrus"
)
-func SetTcpMD5SigSockopts(l *net.TCPListener, address string, key string) error {
- return fmt.Errorf("md5 not supported")
+func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
+ return fmt.Errorf("setting md5 is not supported")
}
-func SetTcpTTLSockopts(conn *net.TCPConn, ttl int) error {
+func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
return fmt.Errorf("setting ttl is not supported")
}
-func SetTcpMinTTLSockopts(conn *net.TCPConn, ttl int) error {
+func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
return fmt.Errorf("setting min ttl is not supported")
}
-func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec int) (*net.TCPConn, error) {
- return nil, fmt.Errorf("md5 active connection unsupported")
+type TCPDialer struct {
+ net.Dialer
+
+ // MD5 authentication password.
+ AuthPassword string
+
+ // The TTL value to set outgoing connection.
+ Ttl uint8
+
+ // The minimum TTL value for incoming packets.
+ TtlMin uint8
+}
+
+func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) {
+ if d.AuthPassword != "" {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": addr,
+ }).Warn("setting md5 for active connection is not supported")
+ }
+ if d.Ttl != 0 {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": addr,
+ }).Warn("setting ttl for active connection is not supported")
+ }
+ if d.TtlMin != 0 {
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": addr,
+ }).Warn("setting min ttl for active connection is not supported")
+ }
+
+ raddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(addr, fmt.Sprintf("%d", port)))
+ if err != nil {
+ return nil, fmt.Errorf("invalid remote address: %s", err)
+ }
+ laddr, err := net.ResolveTCPAddr("tcp", d.LocalAddr.String())
+ if err != nil {
+ return nil, fmt.Errorf("invalid local address: %s", err)
+ }
+
+ dialer := net.Dialer{LocalAddr: laddr, Timeout: d.Timeout}
+ conn, err := dialer.Dial("tcp", raddr.String())
+ if err != nil {
+ return nil, err
+ }
+ return conn.(*net.TCPConn), nil
}