Skip to content

Commit

Permalink
Merge 8c8ca03 into 0f38375
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed May 20, 2020
2 parents 0f38375 + 8c8ca03 commit 9e4a776
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions nettests/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ func (h Tor) Run(ctl *Controller) error {
return ctl.Run(builder, []string{""})
}

type TorTarget struct {
Name string `json:"name"`
Address string `json:"address"`
Type string `json:"type"`
ConnectStatus interface{} `json:"connect"`
HandshakeStatus interface{} `json:"handshake_status"`
}

// TorTestKeys contains the test keys
type TorTestKeys struct {
DirPortTotal int64 `json:"dir_port_total"`
DirPortAccessible int64 `json:"dir_port_accessible"`
IsAnomaly bool `json:"-"`
OBFS4Total int64 `json:"obfs4_total"`
OBFS4Accessible int64 `json:"obfs4_accessible"`
ORPortDirauthTotal int64 `json:"or_port_dirauth_total"`
ORPortDirauthAccessible int64 `json:"or_port_dirauth_accessible"`
ORPortTotal int64 `json:"or_port_total"`
ORPortAccessible int64 `json:"or_port_accessible"`
DirPortTotal int64 `json:"dir_port_total"`
DirPortAccessible int64 `json:"dir_port_accessible"`
IsAnomaly bool `json:"-"`
OBFS4Total int64 `json:"obfs4_total"`
OBFS4Accessible int64 `json:"obfs4_accessible"`
ORPortDirauthTotal int64 `json:"or_port_dirauth_total"`
ORPortDirauthAccessible int64 `json:"or_port_dirauth_accessible"`
ORPortTotal int64 `json:"or_port_total"`
ORPortAccessible int64 `json:"or_port_accessible"`
Targets []TorTarget `json:"targets"`
}

// GetTestKeys generates a summary for a test run
Expand Down Expand Up @@ -63,6 +72,33 @@ func (h Tor) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
(testKeys.OBFS4Accessible <= 0 && testKeys.OBFS4Total > 0) ||
(testKeys.ORPortDirauthAccessible <= 0 && testKeys.ORPortDirauthTotal > 0) ||
(testKeys.ORPortAccessible <= 0 && testKeys.ORPortTotal > 0))

for k := range tk["targets"].(map[string]interface{}) {
t := TorTarget{}
targets := tk["targets"].(map[string]interface{})[k].(map[string]interface{})
summary := targets["summary"].(map[string]interface{})
// Connection Status values
// false: Didn't run (N/A)
// null: No failure a.k.a success
// string: Failure with error string
if summary["connect"] != nil {
connect := summary["connect"].(map[string]interface{})
t.ConnectStatus = connect["failure"]
} else {
t.ConnectStatus = false
}
if summary["handshake"] != nil {
handshake := summary["handshake"].(map[string]interface{})
t.HandshakeStatus = handshake["failure"]
} else {
t.HandshakeStatus = false
}
t.Name = targets["target_name"].(string)
t.Address = targets["target_address"].(string)
t.Type = targets["target_protocol"].(string)
testKeys.Targets = append(testKeys.Targets, t)
}

return testKeys, nil
}

Expand Down

0 comments on commit 9e4a776

Please sign in to comment.