lux/rpc/lux_rpc_data.go

132 lines
2.7 KiB
Go

package rpc
import (
"encoding/xml"
"fmt"
)
type LuxRpcWAN struct {
XMLName xml.Name `xml:"wan"`
Addr4 string `xml:"addr4"`
Addr6 string `xml:"addr6"`
}
type LuxRpcOption struct {
XMLName xml.Name `xml:"option"`
Type int `xml:"type,attr"`
Blob string `xml:",innerxml"`
}
type LuxRpcNetAddr struct {
XMLName xml.Name `xml:"addr"`
Type string `xml:"type,attr"`
Addr string `xml:",innerxml"`
}
type LuxRpcNetInterface struct {
XMLName xml.Name `xml:"if"`
Name string `xml:"name,attr"`
Index int `xml:"idx,attr"`
Addrs []LuxRpcNetAddr `xml:"addr"`
}
type LuxRpcNetIf struct {
XMLName xml.Name `xml:"netif"`
Interfaces []LuxRpcNetInterface `xml:"if"`
}
type LuxRpcState struct {
XMLName xml.Name `xml:"state"`
WAN LuxRpcWAN `xml:"wan"`
NetIf LuxRpcNetIf `xml:"netif"`
Options []LuxRpcOption `xml:"option"`
}
type LuxRpcHost struct {
XMLName xml.Name `xml:"host"`
HostID string `xml:"id,attr"`
Hostname string `xml:"hostname,attr"`
State LuxRpcState `xml:"state"`
}
type LuxRpcRequest struct {
XMLName xml.Name `xml:"request"`
RequestID int `xml:"id,attr"`
Controller string `xml:"controller,attr"`
Command string `xml:"command,attr"`
// Command-specific fields
Hosts []LuxRpcHost `xml:"host"`
}
type LuxRpcKeyNode struct {
XMLName xml.Name `xml:"node"`
ID string `xml:"id,attr"`
KeyBlob string `xml:"key"`
IVBlob string `xml:"iv"`
}
type LuxRpcKeyHost struct {
XMLName xml.Name `xml:"host"`
ID string `xml:"id,attr"`
KeyBlob string `xml:"key"`
IVBlob string `xml:"iv"`
}
type LuxRpcKeyStore struct {
XMLName xml.Name `xml:"keystore"`
Nodes []LuxRpcKeyNode `xml:"node"`
Hosts []LuxRpcKeyHost `xml:"host"`
}
type LuxRpcRoute struct {
XMLName xml.Name `xml:"route"`
Type int `xml:"type,attr"`
ChannelType string `xml:"channelType,attr"`
Target string `xml:"target"`
Source string `xml:"source"`
Destination string `xml:"destination"`
}
func (route *LuxRpcRoute) String() string {
var dir string
switch route.Type {
case 0:
dir = " <-> *"
case 1:
dir = "* <-> "
default:
dir = " <?> "
}
return fmt.Sprintf("%s%s%s %s %s",
route.Target, dir, route.Source,
route.ChannelType, route.Destination)
}
type LuxRpcResponse struct {
XMLName xml.Name `xml:"response"`
RequestID int `xml:"id,attr"`
// Command-specific fields
Keystore LuxRpcKeyStore `xml:"keystore"`
Routes []LuxRpcRoute `xml:"route"`
Hosts []LuxRpcHost `xml:"host"`
NewHostID string `xml:"newHostId"`
NewNodeID string `xml:"newNodeId"`
}
type LuxRpcError struct {
XMLName xml.Name `xml:"error"`
RequestID int `xml:"id,attr"`
ErrorCode int `xml:"code,attr"`
Message string `xml:",innerxml"`
}