depot/packages/networking/hyprspace/rpc/client.go

34 lines
731 B
Go
Raw Normal View History

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
}