2023-01-21 00:37:26 +02:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/rpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func connect(ifname string) *rpc.Client {
|
|
|
|
client, err := rpc.Dial("unix", fmt.Sprintf("/run/hyprspace-rpc.%s.sock", ifname))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("[!] Failed to connect to RPC server: ", err)
|
|
|
|
}
|
|
|
|
return client
|
|
|
|
}
|
|
|
|
|
|
|
|
func Status(ifname string) StatusReply {
|
|
|
|
client := connect(ifname)
|
|
|
|
var reply StatusReply
|
|
|
|
if err := client.Call("HyprspaceRPC.Status", new(Args), &reply); err != nil {
|
|
|
|
log.Fatal("[!] RPC call failed: ", err)
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
|
|
|
|
|
|
|
func Peers(ifname string) PeersReply {
|
|
|
|
client := connect(ifname)
|
|
|
|
var reply PeersReply
|
|
|
|
if err := client.Call("HyprspaceRPC.Peers", new(Args), &reply); err != nil {
|
|
|
|
log.Fatal("[!] RPC call failed: ", err)
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|
2023-01-23 20:27:20 +02:00
|
|
|
|
|
|
|
func Route(ifname string, args RouteArgs) RouteReply {
|
|
|
|
client := connect(ifname)
|
|
|
|
var reply RouteReply
|
|
|
|
if err := client.Call("HyprspaceRPC.Route", args, &reply); err != nil {
|
|
|
|
log.Fatal("[!] RPC call failed: ", err)
|
|
|
|
}
|
|
|
|
return reply
|
|
|
|
}
|