rename read/writeSessionHeader

parent c5759584
......@@ -73,7 +73,7 @@ func (g *Gateway) pingNode(addr modules.NetAddress) error {
UniqueID: g.id,
NetAddress: modules.NetAddress(conn.LocalAddr().String()),
}
if err := writeSessionHeader(conn, ourHeader); err != nil {
if err := exchangeOurHeader(conn, ourHeader); err != nil {
return err
}
......
......@@ -183,11 +183,11 @@ func (g *Gateway) managedAcceptConnv130Peer(conn net.Conn, remoteVersion string)
UniqueID: g.id,
NetAddress: modules.NetAddress(net.JoinHostPort(host, g.port)),
}
remoteHeader, err := readSessionHeader(conn, ourHeader)
remoteHeader, err := exchangeRemoteHeader(conn, ourHeader)
if err != nil {
return err
}
if err := writeSessionHeader(conn, ourHeader); err != nil {
if err := exchangeOurHeader(conn, ourHeader); err != nil {
return err
}
......@@ -400,7 +400,8 @@ func acceptVersionHandshake(conn net.Conn, version string) (remoteVersion string
return remoteVersion, nil
}
func writeSessionHeader(conn net.Conn, ourHeader sessionHeader) error {
// exchangeOurHeader writes ourHeader and reads the remote's error response.
func exchangeOurHeader(conn net.Conn, ourHeader sessionHeader) error {
// Send our header.
if err := encoding.WriteObject(conn, ourHeader); err != nil {
return fmt.Errorf("failed to write header: %v", err)
......@@ -418,7 +419,8 @@ func writeSessionHeader(conn net.Conn, ourHeader sessionHeader) error {
return nil
}
func readSessionHeader(conn net.Conn, ourHeader sessionHeader) (sessionHeader, error) {
// exchangeRemoteHeader reads the remote header and writes an error response.
func exchangeRemoteHeader(conn net.Conn, ourHeader sessionHeader) (sessionHeader, error) {
// Read remote header.
var remoteHeader sessionHeader
if err := encoding.ReadObject(conn, &remoteHeader, maxEncodedSessionHeaderSize); err != nil {
......@@ -447,9 +449,9 @@ func (g *Gateway) managedConnectv130Peer(conn net.Conn, remoteVersion string, re
UniqueID: g.id,
NetAddress: modules.NetAddress(net.JoinHostPort(host, g.port)),
}
if err := writeSessionHeader(conn, ourHeader); err != nil {
if err := exchangeOurHeader(conn, ourHeader); err != nil {
return err
} else if _, err := readSessionHeader(conn, ourHeader); err != nil {
} else if _, err := exchangeRemoteHeader(conn, ourHeader); err != nil {
return err
}
return nil
......
......@@ -214,7 +214,7 @@ func TestListen(t *testing.T) {
NetAddress: "fake",
}
err = writeSessionHeader(conn, header)
err = exchangeOurHeader(conn, header)
if err == nil {
t.Fatal("expected error, got nil")
}
......@@ -235,11 +235,11 @@ func TestListen(t *testing.T) {
}
header.NetAddress = modules.NetAddress(conn.LocalAddr().String())
err = writeSessionHeader(conn, header)
err = exchangeOurHeader(conn, header)
if err != nil {
t.Fatal(err)
}
_, err = readSessionHeader(conn, header)
_, err = exchangeRemoteHeader(conn, header)
if err != nil {
t.Fatal(err)
}
......@@ -633,8 +633,8 @@ func TestConnectRejectsVersions(t *testing.T) {
UniqueID: tt.uniqueID,
NetAddress: modules.NetAddress(conn.LocalAddr().String()),
}
_, err = readSessionHeader(conn, ourHeader)
writeSessionHeader(conn, ourHeader)
_, err = exchangeRemoteHeader(conn, ourHeader)
exchangeOurHeader(conn, ourHeader)
} else if build.VersionCmp(tt.version, handshakeUpgradeVersion) >= 0 {
var dialbackPort string
err = encoding.ReadObject(conn, &dialbackPort, 13)
......
......@@ -36,7 +36,7 @@ func (g *Gateway) load() error {
var nodes []*node
err := persist.LoadJSON(persistMetadata, &nodes, filepath.Join(g.persistDir, nodesFile))
if err != nil {
// COMPATv1.2.1
// COMPATv1.3.0
return g.loadv033persist()
}
for i := range nodes {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment