Ver código fonte

Merge baab8bf6c8 into 40ceb4956c

pull/1785/merge
Shivaram Lingamneni 3 semanas atrás
pai
commit
828b19a239
Nenhuma conta vinculada ao e-mail do autor do commit
3 arquivos alterados com 39 adições e 15 exclusões
  1. 20
    15
      irc/getters.go
  2. 1
    0
      irc/nickserv.go
  3. 18
    0
      irc/socket.go

+ 20
- 15
irc/getters.go Ver arquivo

@@ -47,15 +47,17 @@ func (client *Client) Sessions() (sessions []*Session) {
47 47
 }
48 48
 
49 49
 type SessionData struct {
50
-	ctime     time.Time
51
-	atime     time.Time
52
-	ip        net.IP
53
-	hostname  string
54
-	certfp    string
55
-	deviceID  string
56
-	connInfo  string
57
-	sessionID int64
58
-	caps      []string
50
+	ctime        time.Time
51
+	atime        time.Time
52
+	ip           net.IP
53
+	hostname     string
54
+	certfp       string
55
+	deviceID     string
56
+	connInfo     string
57
+	sessionID    int64
58
+	caps         []string
59
+	bytesRead    uint64
60
+	bytesWritten uint64
59 61
 }
60 62
 
61 63
 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
68 70
 		if session == currentSession {
69 71
 			currentIndex = i
70 72
 		}
73
+		bytesRead, bytesWritten := session.socket.Stats()
71 74
 		data[i] = SessionData{
72
-			atime:     session.lastActive,
73
-			ctime:     session.ctime,
74
-			hostname:  session.rawHostname,
75
-			certfp:    session.certfp,
76
-			deviceID:  session.deviceID,
77
-			sessionID: session.sessionID,
75
+			atime:        session.lastActive,
76
+			ctime:        session.ctime,
77
+			hostname:     session.rawHostname,
78
+			certfp:       session.certfp,
79
+			deviceID:     session.deviceID,
80
+			sessionID:    session.sessionID,
81
+			bytesRead:    bytesRead,
82
+			bytesWritten: bytesWritten,
78 83
 		}
79 84
 		if session.proxiedIP != nil {
80 85
 			data[i].ip = session.proxiedIP

+ 1
- 0
irc/nickserv.go Ver arquivo

@@ -1327,6 +1327,7 @@ func nsClientsListHandler(service *ircService, server *Server, client *Client, p
1327 1327
 				service.Notice(rb, fmt.Sprintf(client.t("IRCv3 CAPs:  %s"), capStr))
1328 1328
 			}
1329 1329
 		}
1330
+		service.Notice(rb, fmt.Sprintf(client.t("Bytes RX/TX: %d / %d"), session.bytesRead, session.bytesWritten))
1330 1331
 	}
1331 1332
 }
1332 1333
 

+ 18
- 0
irc/socket.go Ver arquivo

@@ -33,6 +33,9 @@ type Socket struct {
33 33
 	sendQExceeded bool
34 34
 	finalData     []byte // what to send when we die
35 35
 	finalized     bool
36
+
37
+	bytesRead    uint64
38
+	bytesWritten uint64
36 39
 }
37 40
 
38 41
 // NewSocket returns a new Socket.
@@ -53,6 +56,12 @@ func (socket *Socket) Close() {
53 56
 	socket.wakeWriter()
54 57
 }
55 58
 
59
+func (socket *Socket) Stats() (bytesRead, bytesWritten uint64) {
60
+	socket.Lock()
61
+	defer socket.Unlock()
62
+	return socket.bytesRead, socket.bytesWritten
63
+}
64
+
56 65
 // Read returns a single IRC line from a Socket.
57 66
 func (socket *Socket) Read() (string, error) {
58 67
 	// immediately fail if Close() has been called, even if there's
@@ -64,6 +73,10 @@ func (socket *Socket) Read() (string, error) {
64 73
 	lineBytes, err := socket.conn.ReadLine()
65 74
 	line := string(lineBytes)
66 75
 
76
+	socket.Lock()
77
+	socket.bytesRead += uint64(len(lineBytes))
78
+	socket.Unlock()
79
+
67 80
 	if err == io.EOF {
68 81
 		socket.Close()
69 82
 	}
@@ -93,6 +106,7 @@ func (socket *Socket) Write(data []byte) (err error) {
93 106
 		} else {
94 107
 			socket.buffers = append(socket.buffers, data)
95 108
 			socket.totalLength = prospectiveLen
109
+			socket.bytesWritten += uint64(len(data))
96 110
 		}
97 111
 	}
98 112
 	socket.Unlock()
@@ -134,6 +148,10 @@ func (socket *Socket) BlockingWrite(data []byte) (err error) {
134 148
 		return io.EOF
135 149
 	}
136 150
 
151
+	socket.Lock()
152
+	socket.bytesWritten += uint64(len(data))
153
+	socket.Unlock()
154
+
137 155
 	err = socket.conn.WriteLine(data)
138 156
 	if err != nil {
139 157
 		socket.finalize()

Carregando…
Cancelar
Salvar