Shivaram Lingamneni 2 місяці тому
джерело
коміт
828b19a239
Аккаунт користувача з таким Email не знайдено
3 змінених файлів з 39 додано та 15 видалено
  1. 20
    15
      irc/getters.go
  2. 1
    0
      irc/nickserv.go
  3. 18
    0
      irc/socket.go

+ 20
- 15
irc/getters.go Переглянути файл

47
 }
47
 }
48
 
48
 
49
 type SessionData struct {
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
 func (client *Client) AllSessionData(currentSession *Session, hasPrivs bool) (data []SessionData, currentIndex int) {
63
 func (client *Client) AllSessionData(currentSession *Session, hasPrivs bool) (data []SessionData, currentIndex int) {
68
 		if session == currentSession {
70
 		if session == currentSession {
69
 			currentIndex = i
71
 			currentIndex = i
70
 		}
72
 		}
73
+		bytesRead, bytesWritten := session.socket.Stats()
71
 		data[i] = SessionData{
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
 		if session.proxiedIP != nil {
84
 		if session.proxiedIP != nil {
80
 			data[i].ip = session.proxiedIP
85
 			data[i].ip = session.proxiedIP

+ 1
- 0
irc/nickserv.go Переглянути файл

1327
 				service.Notice(rb, fmt.Sprintf(client.t("IRCv3 CAPs:  %s"), capStr))
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 Переглянути файл

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

Завантаження…
Відмінити
Зберегти