add probe folder
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package proof
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"git.cryptolab.re/foudre/whitepaper_obsero/pkg/geo"
|
||||
"git.cryptolab.re/foudre/whitepaper_obsero/pkg/probe"
|
||||
)
|
||||
|
||||
type Observation struct {
|
||||
Timestamp string `json:"timestamp"`
|
||||
Target string `json:"target"`
|
||||
Status string `json:"status"`
|
||||
HTTPStatus int `json:"http_status_code"`
|
||||
LatencyMs int64 `json:"latency_ms"`
|
||||
Error string `json:"error_message"`
|
||||
Observer ObserverInfo `json:"observer"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type ObserverInfo struct {
|
||||
Address string `json:"address"`
|
||||
Country string `json:"country"`
|
||||
Region string `json:"region"`
|
||||
City string `json:"city"`
|
||||
ProbeVersion string `json:"probe_version"`
|
||||
}
|
||||
|
||||
func BuildProof(result probe.PingResult, loc geo.GeoInfo) Observation {
|
||||
return Observation{
|
||||
Timestamp: result.Timestamp,
|
||||
Target: result.Target,
|
||||
Status: result.Status,
|
||||
HTTPStatus: result.StatusCode,
|
||||
LatencyMs: result.LatencyMs,
|
||||
Error: result.ErrorMsg,
|
||||
Version: "0.1",
|
||||
Observer: ObserverInfo{
|
||||
Address: "0xABCD...1234",
|
||||
Country: loc.Country,
|
||||
Region: loc.Region,
|
||||
City: loc.City,
|
||||
ProbeVersion: "0.1",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func SaveProof(obs Observation, filename string) {
|
||||
file, _ := json.MarshalIndent(obs, "", " ")
|
||||
_ = os.WriteFile(filename, file, 0644)
|
||||
}
|
||||
Reference in New Issue
Block a user