return rttMs as null on error

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-11-25 15:05:49 +01:00 committed by Jakub
parent 47ccf32cdb
commit 464c30a430
2 changed files with 8 additions and 4 deletions

View File

@ -16,7 +16,7 @@ The call takes one struct argument which contains two attributes:
The return value consists of a list of objects representing a result for each mailserver, each containing following attributes:
* `address` - The `enode` address of given mailserver.
* `rtt_ms` - Round Trip Time given in milliseconds. Set to `-1` in case of an error.`
* `rttMs` - Round Trip Time given in milliseconds. Set to `null` in case of an error.`
* `error` - A text of error that caused the ping failure.
# Example
@ -53,7 +53,7 @@ EOL
},
{
"address": "enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@206.189.243.162:999",
"rtt_ms": -1,
"rtt_ms": null,
"error": "tcp check timeout: I/O timeout"
}
]

View File

@ -19,7 +19,7 @@ type PingQuery struct {
type PingResult struct {
ENode string `json:"address"`
RTTMs int `json:"rtt_ms"`
RTTMs *int `json:"rttMs"`
Err *string `json:"error"`
}
@ -28,7 +28,11 @@ func (pr *PingResult) Update(rttMs int, err error) {
errStr := err.Error()
pr.Err = &errStr
}
pr.RTTMs = rttMs
if rttMs > 0 {
pr.RTTMs = &rttMs
} else {
pr.RTTMs = nil
}
}
func enodeToAddr(enodeAddr string) (string, error) {