package station import ( "bytes" jsonv2 "encoding/json/v2" "golang.org/x/sys/unix" ) // SoftwareName and SoftwareVersion are the identity sent to the reflector // after login. Edit them here. const ( SoftwareName = "funknetz" SoftwareVersion = "1.0.0" ) type nodeSoftware struct { SW string `json:"sw"` SWVer string `json:"swVer"` ProjVer string `json:"projVer"` MachineArch string `json:"machineArch,omitempty"` } func softwareIdentityBody() ([]byte, error) { raw, err := marshalNode(false) if err != nil { return nil, err } return appendString(nil, string(raw)), nil } func nodeInfoV3(iv, key []byte) ([]byte, error) { raw, err := marshalNode(true) if err != nil { return nil, err } body := appendBlob(nil, iv) body = appendBlob(body, key) return appendString(body, string(raw)), nil } func marshalNode(arch bool) ([]byte, error) { info := nodeSoftware{ SW: SoftwareName, SWVer: SoftwareVersion, ProjVer: SoftwareVersion, } if arch { if name, ok := machineArch(); ok { info.MachineArch = name } } return jsonv2.Marshal(info) } func machineArch() (string, bool) { var u unix.Utsname if err := unix.Uname(&u); err != nil { return "", false } b := u.Machine[:] if i := bytes.IndexByte(b, 0); i >= 0 { b = b[:i] } if len(b) == 0 { return "", false } return string(b), true }