A reflector that has moved to 3.0 will not accept a station that always announces 2.0, and a 2.x reflector still needs one explicit plaintext session. Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
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
|
|
}
|