Commit 99ea2b93 authored by Kirill Smelkov's avatar Kirill Smelkov

X unexport neonet.DialEncTryOrder

parent c3fb22a4
......@@ -39,6 +39,7 @@ import (
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/go123/xsync"
"lab.nexedi.com/kirr/neo/go/neo/internal/tneonet"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
"lab.nexedi.com/kirr/neo/go/neo/proto"
bsqlite "lab.nexedi.com/kirr/neo/go/neo/storage/sqlite"
......@@ -514,9 +515,9 @@ func withNEO(t *testing.T, f func(t *testing.T, nsrv NEOSrv, ndrv *Client), optv
// For example if NEO/py server implments only M encoding,
// testing with N,M verifies retry after handshaking with
// enc=N.
encTryOrder0 := neonet.DialEncTryOrder
encTryOrder0 := *tneonet.DialEncTryOrder
defer func() {
neonet.DialEncTryOrder = encTryOrder0
*tneonet.DialEncTryOrder = encTryOrder0
}()
for i := range encTryOrder0 {
......@@ -551,7 +552,7 @@ func withNEO(t *testing.T, f func(t *testing.T, nsrv NEOSrv, ndrv *Client), optv
}
neonet.DialEncTryOrder = encv
*tneonet.DialEncTryOrder = encv
ndrv, _, err := neoOpen(nsrv.URL(),
&zodb.DriverOptions{ReadOnly: true}); X(err)
defer func() {
......@@ -561,7 +562,7 @@ func withNEO(t *testing.T, f func(t *testing.T, nsrv NEOSrv, ndrv *Client), optv
// verify that link was established with either:
// - encv[0] encoding (NEO/go = server supports autodetection)
// - server encoding (NEO/py)
encOK := neonet.DialEncTryOrder[0]
encOK := (*tneonet.DialEncTryOrder)[0]
if noautodetect {
encOK = srvEnc
}
......
// Copyright (C) 2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package tneonet provides testing hooks for neonet package.
package tneonet
import (
"lab.nexedi.com/kirr/neo/go/neo/proto"
)
var DialEncTryOrder *[]proto.Encoding // = &neonet.dialEncTryOrder
......@@ -34,6 +34,7 @@ import (
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/internal/xcontext"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/neo/go/neo/internal/tneonet"
"lab.nexedi.com/kirr/neo/go/neo/proto"
)
......@@ -44,7 +45,7 @@ import (
// do not have such uses.
func _HandshakeClient(ctx context.Context, conn net.Conn) (*NodeLink, error) {
return handshakeClient(ctx, conn, proto.Version, DialEncTryOrder[0])
return handshakeClient(ctx, conn, proto.Version, dialEncTryOrder[0])
}
func _HandshakeServer(ctx context.Context, conn net.Conn) (*NodeLink, error) {
......@@ -274,24 +275,25 @@ func rxHello(errctx string, rx *xbufReader) (enc proto.Encoding, version uint32,
// ---- Dial & Listen at NodeLink level ----
// DialEncTryOrder is the order of trials for encoding when establishing a NEO link from client side.
// dialEncTryOrder is the order of trials for encoding when establishing a NEO link from client side.
//
// NEO/go server autodetects client preferred encoding and adjusts to that, but
// NEO/py rejects connections if client encoding does not exactly match server.
//
// To autodetect what NEO/py server uses DialLink retries dial + handshake with
// client-preferred encodings in the order specified by DialEncTryOrder.
// client-preferred encodings in the order specified by dialEncTryOrder.
//
// NOTE tests change this to verify that autodetection of NEO/py server
// encoding actually works.
//
// XXX unexport
var DialEncTryOrder = []proto.Encoding{'N', 'M'}
var dialEncTryOrder = []proto.Encoding{'N', 'M'}
func init() {
tneonet.DialEncTryOrder = &dialEncTryOrder
}
// DialLink connects to address on given network, performs NEO protocol
// handshake and wraps the connection as NodeLink.
func DialLink(ctx context.Context, net xnet.Networker, addr string) (link *NodeLink, err error) {
for _, enc := range DialEncTryOrder {
for _, enc := range dialEncTryOrder {
peerConn, err := net.Dial(ctx, addr)
if err != nil {
return nil, err
......
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