Feature: Tunnel the device protocol through a reverse proxy over WebSocket
This commit is contained in:
1 parent
de621aa555
commit
d4f312c9d8
20 files changed
+1994
-63
No files matched your search
@@ -61,6 +61,10 @@ type Context struct {
|
||||
closed atomic.Bool
|
||||
sendLock sync.Mutex
|
||||
server *Manager
|
||||
|
||||
// peerIPOverride replaces the address derived from RemoteAddr when a
|
||||
// trusted reverse proxy reports the device's real address.
|
||||
peerIPOverride string
|
||||
}
|
||||
|
||||
// FlagType represents the protocol flag type
|
||||
@@ -156,12 +160,28 @@ func (c *Context) IsClosed() bool {
|
||||
|
||||
// GetPeerIP returns the peer IP address
|
||||
func (c *Context) GetPeerIP() string {
|
||||
c.mu.RLock()
|
||||
override := c.peerIPOverride
|
||||
c.mu.RUnlock()
|
||||
if override != "" {
|
||||
return override
|
||||
}
|
||||
if host, _, err := net.SplitHostPort(c.RemoteAddr); err == nil {
|
||||
return host
|
||||
}
|
||||
return c.RemoteAddr
|
||||
}
|
||||
|
||||
// SetPeerIP overrides the address reported by GetPeerIP. The server uses it
|
||||
// when a trusted reverse proxy reports a device's real address, so per-IP
|
||||
// accounting, logging and the ConnAuth sub-connection binding all see the
|
||||
// device rather than the proxy.
|
||||
func (c *Context) SetPeerIP(ip string) {
|
||||
c.mu.Lock()
|
||||
c.peerIPOverride = ip
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// AliveTime returns how long the connection has been alive
|
||||
func (c *Context) AliveTime() time.Duration {
|
||||
return time.Since(c.OnlineTime)
|
||||
|
||||
Reference in new issue
Block a user