Let the config choose protocol 2 or 3, and fall back for one session only.
The default stays v2. A reflector that refuses that version and names the other gets one session of it, then the station announces the configured protocol again. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -194,6 +194,23 @@ func parseVersion(b []byte) (uint16, uint16, error) {
|
||||
}
|
||||
|
||||
var atMostVersion = regexp.MustCompile(`^Unsupported protocol version \d+\.\d+\. May be at most (\d+)\.(\d+)\.$`)
|
||||
var atLeastVersion = regexp.MustCompile(`^Unsupported protocol version \d+\.\d+\. Must be at least (\d+)\.(\d+)\.$`)
|
||||
|
||||
// wantsOther reports that the reflector refused the announced major and named the other one.
|
||||
func wantsOther(announced uint16, msg string) bool {
|
||||
if announced >= 3 {
|
||||
return fallback20(msg)
|
||||
}
|
||||
return fallback30(msg)
|
||||
}
|
||||
|
||||
// acceptsOther reports that a downgrade names the protocol this station did not announce.
|
||||
func acceptsOther(announced, gotMajor, gotMinor uint16) bool {
|
||||
if announced >= 3 {
|
||||
return gotMajor == 2
|
||||
}
|
||||
return gotMajor == 3 && gotMinor == 0
|
||||
}
|
||||
|
||||
// fallback20 reports that the reflector's maximum is at least 2.0 and below 3.0.
|
||||
func fallback20(msg string) bool {
|
||||
@@ -209,6 +226,20 @@ func fallback20(msg string) bool {
|
||||
return !versionBelow(major, minor, 2, 0) && versionBelow(major, minor, 3, 0)
|
||||
}
|
||||
|
||||
// fallback30 reports that the reflector's minimum is exactly 3.0.
|
||||
func fallback30(msg string) bool {
|
||||
m := atLeastVersion.FindStringSubmatch(msg)
|
||||
if m == nil {
|
||||
return false
|
||||
}
|
||||
major, err1 := strconv.Atoi(m[1])
|
||||
minor, err2 := strconv.Atoi(m[2])
|
||||
if err1 != nil || err2 != nil {
|
||||
return false
|
||||
}
|
||||
return major == 3 && minor == 0
|
||||
}
|
||||
|
||||
func versionBelow(major, minor, maj, min int) bool {
|
||||
if major != maj {
|
||||
return major < maj
|
||||
|
||||
Reference in New Issue
Block a user