Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Conn struct {
// connection. The rtt is measured in nanoseconds.
rtt atomic.Int64

// systemStart is the timestamp indicating when the remote system was started,
// collected via timestamps.
systemStart time.Time

closing atomic.Int64

ctx context.Context
Expand Down Expand Up @@ -690,6 +694,11 @@ func (conn *Conn) writeTo(p []byte, raddr net.Addr) error {
return nil
}

// SystemUptime returns the uptime of the senders system or client.
func (conn *Conn) SystemUptime() time.Duration {
return time.Since(conn.systemStart)
}

// startTime is the time the system or client was started.
var startTime = time.Now()

Expand Down
1 change: 1 addition & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (h listenerConnectionHandler) handleConnectionRequest(conn *Conn, b []byte)
if err := pk.UnmarshalBinary(b); err != nil {
return fmt.Errorf("read CONNECTION_REQUEST: %w", err)
}
conn.systemStart = time.Now().Add(-time.Millisecond * time.Duration(pk.RequestTime))
return conn.send(&message.ConnectionRequestAccepted{ClientAddress: resolve(conn.raddr), PingTime: pk.RequestTime, PongTime: timestamp()})
}

Expand Down