Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! chore: rework RPC version negotiation
  • Loading branch information
deansheather committed Dec 4, 2024
commit 6fa42207726826f552f007277c54a387d6fa5bbc
4 changes: 2 additions & 2 deletions vpn/speaker_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSpeaker_RawPeer(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expectedHandshake, string(b[:n]))

_, err = mp.Write([]byte("codervpn manager 1.0\n"))
_, err = mp.Write([]byte("codervpn manager 1.3,2.1\n"))
require.NoError(t, err)

err = testutil.RequireRecvCtx(ctx, t, errCh)
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestSpeaker_HandshakeInvalid(t *testing.T) {
}{
{name: "preamble", handshake: "ssh manager 1.0\n"},
{name: "2components", handshake: "ssh manager\n"},
{name: "newmajor", handshake: "codervpn manager 2.0\n"},
{name: "newmajors", handshake: "codervpn manager 2.0,3.0\n"},
{name: "0version", handshake: "codervpn 0.1 manager\n"},
{name: "unknown_role", handshake: "codervpn 1.0 supervisor\n"},
{name: "unexpected_role", handshake: "codervpn 1.0 tunnel\n"},
Expand Down
11 changes: 7 additions & 4 deletions vpn/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ParseRPCVersionList(str string) (RPCVersionList, error) {
for i, v := range split {
version, err := ParseRPCVersion(v)
if err != nil {
return RPCVersionList{}, xerrors.Errorf("invalid version string: %s", v)
return RPCVersionList{}, xerrors.Errorf("invalid version list: %s", str)
}
versions[i] = version
}
Expand All @@ -105,11 +105,14 @@ func (vl RPCVersionList) Validate() error {
if len(vl.Versions) == 0 {
return xerrors.New("no versions")
}
for i := 1; i < len(vl.Versions); i++ {
if vl.Versions[i-1].Major == vl.Versions[i].Major {
for i := 0; i < len(vl.Versions); i++ {
if vl.Versions[i].Major == 0 {
return xerrors.Errorf("invalid version: %s", vl.Versions[i].String())
}
if i > 0 && vl.Versions[i-1].Major == vl.Versions[i].Major {
return xerrors.Errorf("duplicate major version: %d", vl.Versions[i].Major)
}
if vl.Versions[i-1].Major > vl.Versions[i].Major {
if i > 0 && vl.Versions[i-1].Major > vl.Versions[i].Major {
return xerrors.Errorf("versions are not sorted")
}
}
Expand Down
Loading