From aabaa128c4aa4784ef7ba9f0e41f038b2c5e340e Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 26 Nov 2017 13:29:09 +1300 Subject: [PATCH] move some UserInfo properties into separate adc/nmdc sub structs --HG-- branch : adc --- NmdcProtocol_test.go | 28 ++++++++++++++++++---------- UserInfo.go | 30 ++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/NmdcProtocol_test.go b/NmdcProtocol_test.go index 0b513c5..70c4f34 100644 --- a/NmdcProtocol_test.go +++ b/NmdcProtocol_test.go @@ -24,23 +24,27 @@ func TestMyINFOParse(t *testing.T) { ClientVersion: "1.4.3", Email: "xyz@example.com", ShareSize: 53054999578, - ConnectionMode: CONNECTIONMODE_PASSIVE, Flag: FLAG_NORMAL, Slots: 1, - Speed: "0.0", HubsUnregistered: 9, HubsRegistered: 0, HubsOperator: 2, + UserInfo_NMDCOnly: UserInfo_NMDCOnly{ + ConnectionMode: CONNECTIONMODE_PASSIVE, + Speed: "0.0", + }, }, }, myInfoTestPair{ in: "$ALL ixxxxxxx0 $P$10A$$0$", expect: UserInfo{ - Nick: "ixxxxxxx0", - ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings - ConnectionMode: CONNECTIONMODE_PASSIVE, - Flag: UserFlag(rune('A')), - Speed: "1", + Nick: "ixxxxxxx0", + ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings + Flag: UserFlag(rune('A')), + UserInfo_NMDCOnly: UserInfo_NMDCOnly{ + ConnectionMode: CONNECTIONMODE_PASSIVE, + Speed: "1", + }, }, }, myInfoTestPair{ @@ -49,11 +53,13 @@ func TestMyINFOParse(t *testing.T) { Nick: "SXXXX_XXXXXXR", ClientTag: "ncdc", ClientVersion: "1.19.1-12-g5561", - ConnectionMode: CONNECTIONMODE_PASSIVE, Flag: UserFlag(rune('Q')), Slots: 10, - Speed: "0.00", HubsUnregistered: 1, + UserInfo_NMDCOnly: UserInfo_NMDCOnly{ + ConnectionMode: CONNECTIONMODE_PASSIVE, + Speed: "0.00", + }, }, }, myInfoTestPair{ @@ -63,10 +69,12 @@ func TestMyINFOParse(t *testing.T) { Description: "desccccc", ClientTag: "HexChat", ClientVersion: "2.12.1", - ConnectionMode: CONNECTIONMODE_PASSIVE, Flag: UserFlag(rune('p')), HubsUnregistered: 1, Slots: 0, + UserInfo_NMDCOnly: UserInfo_NMDCOnly{ + ConnectionMode: CONNECTIONMODE_PASSIVE, + }, }, }, } diff --git a/UserInfo.go b/UserInfo.go index cc51f44..f1690cd 100644 --- a/UserInfo.go +++ b/UserInfo.go @@ -8,21 +8,43 @@ type UserInfo struct { ClientVersion string Email string ShareSize uint64 - ConnectionMode ConnectionMode Flag UserFlag Slots uint64 - Speed string HubsUnregistered uint64 HubsRegistered uint64 HubsOperator uint64 IsOperator bool - IPAddress string + + UserInfo_NMDCOnly + UserInfo_ADCOnly +} + +type UserInfo_NMDCOnly struct { + Speed string + IPAddress string + ConnectionMode ConnectionMode +} + +type UserInfo_ADCOnly struct { + SharedFiles uint64 + UploadSpeedBps uint64 + DownloadSpeedBps uint64 + IsBot bool + IsRegistered bool + IsSuperUser bool + IsHubOwner bool + IPv4Address string // Passive <==> these fields are not set + IPv6Address string + IPv4UDPPort uint + IPv6UDPPort uint } func NewUserInfo(username string) *UserInfo { return &UserInfo{ Nick: username, - ConnectionMode: CONNECTIONMODE_PASSIVE, HubsUnregistered: 1, + UserInfo_NMDCOnly: UserInfo_NMDCOnly{ + ConnectionMode: CONNECTIONMODE_PASSIVE, + }, } }