mirror of
https://github.com/ergochat/ergo.git
synced 2026-03-25 08:38:18 +01:00
Merge baab8bf6c8c6a9d09531b6488ce26a286cc68e9f into 40ceb4956c40f345c2a2095ab273b27476e36698
This commit is contained in:
commit
828b19a239
@ -47,15 +47,17 @@ func (client *Client) Sessions() (sessions []*Session) {
|
||||
}
|
||||
|
||||
type SessionData struct {
|
||||
ctime time.Time
|
||||
atime time.Time
|
||||
ip net.IP
|
||||
hostname string
|
||||
certfp string
|
||||
deviceID string
|
||||
connInfo string
|
||||
sessionID int64
|
||||
caps []string
|
||||
ctime time.Time
|
||||
atime time.Time
|
||||
ip net.IP
|
||||
hostname string
|
||||
certfp string
|
||||
deviceID string
|
||||
connInfo string
|
||||
sessionID int64
|
||||
caps []string
|
||||
bytesRead uint64
|
||||
bytesWritten uint64
|
||||
}
|
||||
|
||||
func (client *Client) AllSessionData(currentSession *Session, hasPrivs bool) (data []SessionData, currentIndex int) {
|
||||
@ -68,13 +70,16 @@ func (client *Client) AllSessionData(currentSession *Session, hasPrivs bool) (da
|
||||
if session == currentSession {
|
||||
currentIndex = i
|
||||
}
|
||||
bytesRead, bytesWritten := session.socket.Stats()
|
||||
data[i] = SessionData{
|
||||
atime: session.lastActive,
|
||||
ctime: session.ctime,
|
||||
hostname: session.rawHostname,
|
||||
certfp: session.certfp,
|
||||
deviceID: session.deviceID,
|
||||
sessionID: session.sessionID,
|
||||
atime: session.lastActive,
|
||||
ctime: session.ctime,
|
||||
hostname: session.rawHostname,
|
||||
certfp: session.certfp,
|
||||
deviceID: session.deviceID,
|
||||
sessionID: session.sessionID,
|
||||
bytesRead: bytesRead,
|
||||
bytesWritten: bytesWritten,
|
||||
}
|
||||
if session.proxiedIP != nil {
|
||||
data[i].ip = session.proxiedIP
|
||||
|
||||
@ -1327,6 +1327,7 @@ func nsClientsListHandler(service *ircService, server *Server, client *Client, p
|
||||
service.Notice(rb, fmt.Sprintf(client.t("IRCv3 CAPs: %s"), capStr))
|
||||
}
|
||||
}
|
||||
service.Notice(rb, fmt.Sprintf(client.t("Bytes RX/TX: %d / %d"), session.bytesRead, session.bytesWritten))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,6 +33,9 @@ type Socket struct {
|
||||
sendQExceeded bool
|
||||
finalData []byte // what to send when we die
|
||||
finalized bool
|
||||
|
||||
bytesRead uint64
|
||||
bytesWritten uint64
|
||||
}
|
||||
|
||||
// NewSocket returns a new Socket.
|
||||
@ -53,6 +56,12 @@ func (socket *Socket) Close() {
|
||||
socket.wakeWriter()
|
||||
}
|
||||
|
||||
func (socket *Socket) Stats() (bytesRead, bytesWritten uint64) {
|
||||
socket.Lock()
|
||||
defer socket.Unlock()
|
||||
return socket.bytesRead, socket.bytesWritten
|
||||
}
|
||||
|
||||
// Read returns a single IRC line from a Socket.
|
||||
func (socket *Socket) Read() (string, error) {
|
||||
// immediately fail if Close() has been called, even if there's
|
||||
@ -64,6 +73,10 @@ func (socket *Socket) Read() (string, error) {
|
||||
lineBytes, err := socket.conn.ReadLine()
|
||||
line := string(lineBytes)
|
||||
|
||||
socket.Lock()
|
||||
socket.bytesRead += uint64(len(lineBytes))
|
||||
socket.Unlock()
|
||||
|
||||
if err == io.EOF {
|
||||
socket.Close()
|
||||
}
|
||||
@ -93,6 +106,7 @@ func (socket *Socket) Write(data []byte) (err error) {
|
||||
} else {
|
||||
socket.buffers = append(socket.buffers, data)
|
||||
socket.totalLength = prospectiveLen
|
||||
socket.bytesWritten += uint64(len(data))
|
||||
}
|
||||
}
|
||||
socket.Unlock()
|
||||
@ -134,6 +148,10 @@ func (socket *Socket) BlockingWrite(data []byte) (err error) {
|
||||
return io.EOF
|
||||
}
|
||||
|
||||
socket.Lock()
|
||||
socket.bytesWritten += uint64(len(data))
|
||||
socket.Unlock()
|
||||
|
||||
err = socket.conn.WriteLine(data)
|
||||
if err != nil {
|
||||
socket.finalize()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user