mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
don't spam searches for unused connections. todo: timeout old connections somehow
This commit is contained in:
parent
70774fc3de
commit
5ea864869a
3 changed files with 46 additions and 37 deletions
|
@ -3,6 +3,7 @@ package tuntap
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
|
||||
)
|
||||
|
@ -10,11 +11,21 @@ import (
|
|||
type tunConn struct {
|
||||
tun *TunAdapter
|
||||
conn *yggdrasil.Conn
|
||||
addr address.Address
|
||||
snet address.Subnet
|
||||
send chan []byte
|
||||
stop chan interface{}
|
||||
}
|
||||
|
||||
func (s *tunConn) close() {
|
||||
s.tun.mutex.Lock()
|
||||
s._close_nomutex()
|
||||
s.tun.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (s *tunConn) _close_nomutex() {
|
||||
delete(s.tun.addrToConn, s.addr)
|
||||
delete(s.tun.subnetToConn, s.snet)
|
||||
close(s.stop)
|
||||
}
|
||||
|
||||
|
@ -32,6 +43,7 @@ func (s *tunConn) reader() error {
|
|||
b := make([]byte, 65535)
|
||||
for {
|
||||
go func() {
|
||||
// TODO read timeout and close
|
||||
if n, err = s.conn.Read(b); err != nil {
|
||||
s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn read error:", err)
|
||||
return
|
||||
|
@ -72,6 +84,7 @@ func (s *tunConn) writer() error {
|
|||
if !ok {
|
||||
return errors.New("send closed")
|
||||
}
|
||||
// TODO write timeout and close
|
||||
if _, err := s.conn.Write(b); err != nil {
|
||||
s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue