fix conflicts with nodeinfo and update that for new crypto type names

This commit is contained in:
Arceliar 2018-12-15 18:11:02 -06:00
commit 28c7d75a20
10 changed files with 385 additions and 66 deletions

View file

@ -35,14 +35,6 @@ const tcp_msgSize = 2048 + 65535 // TODO figure out what makes sense
const default_tcp_timeout = 6 * time.Second
const tcp_ping_interval = (default_tcp_timeout * 2 / 3)
// Wrapper function for non tcp/ip connections.
func setNoDelay(c net.Conn, delay bool) {
tcp, ok := c.(*net.TCPConn)
if ok {
tcp.SetNoDelay(delay)
}
}
// The TCP listener and information about active TCP connections, to avoid duplication.
type tcpInterface struct {
core *Core
@ -62,6 +54,18 @@ type tcpInfo struct {
remoteAddr string
}
// Wrapper function to set additional options for specific connection types.
func (iface *tcpInterface) setExtraOptions(c net.Conn) {
switch sock := c.(type) {
case *net.TCPConn:
sock.SetNoDelay(true)
sock.SetKeepAlive(true)
sock.SetKeepAlivePeriod(iface.tcp_timeout)
// TODO something for socks5
default:
}
}
// Returns the address of the listener.
func (iface *tcpInterface) getAddr() *net.TCPAddr {
return iface.serv.Addr().(*net.TCPAddr)
@ -209,6 +213,7 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
// It defers a bunch of cleanup stuff to tear down all of these things when the reader exists (e.g. due to a closed connection or a timeout).
func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
defer sock.Close()
iface.setExtraOptions(sock)
// Get our keys
myLinkPub, myLinkPriv := crypto.NewBoxKeys() // ephemeral link keys
meta := version_getBaseMetadata()
@ -346,7 +351,6 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
out <- msg
}
p.close = func() { sock.Close() }
setNoDelay(sock, true)
go p.linkLoop()
defer func() {
// Put all of our cleanup here...