summaryrefslogtreecommitdiff
path: root/src/hub
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-05-19 01:02:34 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-05-19 01:04:21 +0200
commitda5b5cade37443ba4491f69e1d84748379cc7f07 (patch)
tree53caa6517751336a88926e289a1901d9145bf664 /src/hub
parentadded some basic sanity checks @ decoder (diff)
added improved sanity checks
Diffstat (limited to 'src/hub')
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5srv.go56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srv.go b/src/hub/src/spreadspace.org/sfive/s5srv.go
index ee1cba0..6b5f030 100644
--- a/src/hub/src/spreadspace.org/sfive/s5srv.go
+++ b/src/hub/src/spreadspace.org/sfive/s5srv.go
@@ -58,46 +58,58 @@ type Server struct {
appendManyChan chan appendManyToken
}
-func (srv Server) Anonymize(update *UpdateFull) *UpdateFull {
- anonymized := []Client{}
+func (srv Server) transform(update *UpdateFull) *UpdateFull {
+ bytesSentTotal := uint(0)
+ clients := []Client{}
for _, client := range update.Data.Clients {
- aIP, err := srv.anonymization.Anonymize(client.IP)
- if err != nil {
- s5l.Printf("anonymization: failed: %v", err)
- } else {
- client.IP = aIP
+ bytesSentTotal += client.BytesSent
+
+ // TODO: add GeoIP lookup here
+
+ if srv.anonymization != nil {
+ if aIP, err := srv.anonymization.Anonymize(client.IP); err != nil {
+ s5l.Printf("transform: anonymization failed: %v", err)
+ } else {
+ client.IP = aIP
+ }
+ }
+
+ clients = append(clients, client)
+ }
+ update.Data.Clients = clients
+
+ if uint(len(update.Data.Clients)) > update.Data.ClientCount {
+ if update.Data.ClientCount > 0 {
+ s5l.Printf("transform: fixing client-count: %d -> %d", update.Data.ClientCount, len(update.Data.Clients))
}
- anonymized = append(anonymized, client)
+ update.Data.ClientCount = uint(len(update.Data.Clients))
}
- update.Data.Clients = anonymized
+ if bytesSentTotal > update.Data.BytesSent {
+ if update.Data.BytesSent > 0 {
+ s5l.Printf("transform: fixing bytes-sent: %d -> %d", update.Data.BytesSent, bytesSentTotal)
+ }
+ update.Data.BytesSent = bytesSentTotal
+ }
+
return update
}
-func (srv Server) AnonymizeMany(updates []*UpdateFull) []*UpdateFull {
- anonymized := []*UpdateFull{}
+func (srv Server) transformMany(updates []*UpdateFull) {
for _, update := range updates {
- anonymized = append(anonymized, srv.Anonymize(update))
+ srv.transform(update)
}
- return anonymized
}
-// TODO: do a sanity check for input data
-// TODO: add GeoIP lookup befor anonymization
-
func (srv Server) appendWorker(idx int) {
for {
select {
case <-srv.quit:
return
case token := <-srv.appendChan:
- if srv.anonymization != nil {
- token.update = srv.Anonymize(token.update)
- }
+ srv.transform(token.update)
token.response <- srv.store.Append(token.update)
case token := <-srv.appendManyChan:
- if srv.anonymization != nil {
- token.updates = srv.AnonymizeMany(token.updates)
- }
+ srv.transformMany(token.updates)
token.response <- srv.store.AppendMany(token.updates)
}
}