mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-13 02:10:56 +01:00
9203690033
Code cleaning around the util/net package. The goal was to write a more understandable source code but modify nothing on the logic. Protect the WireGuard UDP listeners with marks. The implementation can support the VPN permission revocation events in thread safe way. It will be important if we start to support the running time route and DNS update features. - uniformize the file name convention: [struct_name] _ [functions] _ [os].go - code cleaning in net_linux.go - move env variables to env.go file
32 lines
588 B
Go
32 lines
588 B
Go
//go:build !ios
|
|
|
|
package net
|
|
|
|
import (
|
|
"net"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// Conn wraps a net.Conn to override the Close method
|
|
type Conn struct {
|
|
net.Conn
|
|
ID ConnectionID
|
|
}
|
|
|
|
// Close overrides the net.Conn Close method to execute all registered hooks after closing the connection
|
|
func (c *Conn) Close() error {
|
|
err := c.Conn.Close()
|
|
|
|
dialerCloseHooksMutex.RLock()
|
|
defer dialerCloseHooksMutex.RUnlock()
|
|
|
|
for _, hook := range dialerCloseHooks {
|
|
if err := hook(c.ID, &c.Conn); err != nil {
|
|
log.Errorf("Error executing dialer close hook: %v", err)
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|