Speak protocol 3.0 and fall back to 2.0 only when that is the reflector's maximum.
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>
This commit is contained in:
+53
-8
@@ -1,6 +1,11 @@
|
||||
package station
|
||||
|
||||
import jsonv2 "encoding/json/v2"
|
||||
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.
|
||||
@@ -9,16 +14,56 @@ const (
|
||||
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 := jsonv2.Marshal(struct {
|
||||
SW string `json:"sw"`
|
||||
SWVer string `json:"swVer"`
|
||||
}{
|
||||
SW: SoftwareName,
|
||||
SWVer: SoftwareVersion,
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user