Add peer node sync status in GUI (fixes #46)

This commit is contained in:
Jakob Borg
2014-02-13 12:41:37 +01:00
parent c171780c0d
commit 9f63feef30
3 changed files with 61 additions and 29 deletions

View File

@@ -158,6 +158,7 @@ type ConnectionInfo struct {
Address string
ClientID string
ClientVersion string
Completion int
}
// ConnectionStats returns a map with connection statistics for each connected node.
@@ -166,7 +167,14 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
RemoteAddr() net.Addr
}
m.gmut.RLock()
m.pmut.RLock()
m.rmut.RLock()
var tot int
for _, f := range m.global {
tot += f.Size()
}
var res = make(map[string]ConnectionInfo)
for node, conn := range m.protoConn {
@@ -178,10 +186,22 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo {
if nc, ok := m.rawConn[node].(remoteAddrer); ok {
ci.Address = nc.RemoteAddr().String()
}
var have int
for _, f := range m.remote[node] {
if f.Equals(m.global[f.Name]) {
have += f.Size()
}
}
ci.Completion = 100 * have / tot
res[node] = ci
}
m.rmut.RUnlock()
m.pmut.RUnlock()
m.gmut.RUnlock()
return res
}