add probe folder

This commit is contained in:
2025-04-29 23:31:22 +02:00
parent e540cdefc0
commit 371b44422b
5 changed files with 234 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package main
import (
"fmt"
"os"
"git.cryptolab.re/foudre/whitepaper_obsero/pkg/geo"
"git.cryptolab.re/foudre/whitepaper_obsero/pkg/probe"
"git.cryptolab.re/foudre/whitepaper_obsero/pkg/proof"
)
func main() {
target := "https://example.com"
location := geo.GetGeoLocation()
result := probe.HttpPing(target)
observation := proof.BuildProof(result, location)
proof.SaveProof(observation, "proof_http_result.json")
fmt.Println("✅ Proof generated and saved.")
}
+24
View File
@@ -0,0 +1,24 @@
package geo
import (
"encoding/json"
"net/http"
)
type GeoInfo struct {
Country string `json:"country"`
Region string `json:"regionName"`
City string `json:"city"`
}
func GetGeoLocation() GeoInfo {
resp, err := http.Get("http://ip-api.com/json")
if err != nil {
return GeoInfo{Country: "Unknown", Region: "Unknown", City: "Unknown"}
}
defer resp.Body.Close()
var info GeoInfo
json.NewDecoder(resp.Body).Decode(&info)
return info
}
+42
View File
@@ -0,0 +1,42 @@
package probe
import (
"net/http"
"time"
)
type PingResult struct {
Target string
Status string
StatusCode int
LatencyMs int64
ErrorMsg string
Timestamp string
}
func HttpPing(target string) PingResult {
start := time.Now()
resp, err := http.Get(target)
latency := time.Since(start).Milliseconds()
timestamp := time.Now().UTC().Format(time.RFC3339)
result := PingResult{
Target: target,
Timestamp: timestamp,
}
if err != nil {
result.Status = "down"
result.LatencyMs = 0
result.StatusCode = 0
result.ErrorMsg = err.Error()
} else {
defer resp.Body.Close()
result.Status = "up"
result.LatencyMs = latency
result.StatusCode = resp.StatusCode
result.ErrorMsg = ""
}
return result
}
+52
View File
@@ -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)
}
+96
View File
@@ -0,0 +1,96 @@
# 🛰️ Obsero Probe
Lightweight monitoring agent for generating Proof-of-Observability JSON files.
This probe performs HTTP health checks, automatically geolocates itself, and exports signed observation files compliant with the Obsero specification.
---
## ⚙️ Requirements
- Go 1.21+
- Internet access (for geo lookup and ping)
---
## 🚀 Quick Start
### 1. Clone & Enter
```bash
cd probe
```
### 2. Install dependencies
```bash
go mod tidy
```
### 3. Run the probe
```bash
go run ./cmd/obsero-probe
```
This will:
- Ping `https://example.com`
- Auto-detect country, city and region
- Output a file named `proof_http_result.json`
---
## 📄 Output Format
The output file is a valid Obsero proof:
```json
{
"timestamp": "2025-04-29T14:00:00Z",
"target": "https://example.com",
"status": "up",
"http_status_code": 200,
"latency_ms": 145,
"error_message": null,
"observer": {
"address": "0xABCD...1234",
"country": "France",
"region": "Île-de-France",
"city": "Paris",
"probe_version": "0.1"
},
"version": "0.1"
}
```
---
## 📦 Next steps
- Add CLI support (`--target`, `--output`)
- Add cryptographic signature of the proof
- Upload to IPFS
- Submit hash + CID on Base chain
---
## 📁 Structure
```
probe/
├── cmd/
│ └── obsero-probe/
│ └── main.go # CLI entrypoint
├── pkg/
│ ├── geo/ # IP geolocation
│ ├── probe/ # HTTP ping logic
│ └── proof/ # Proof struct + output
├── go.mod
├── go.sum
```
---
## 📜 License
MIT — Cryptolab.re