Commit 20f76288 authored by Kirill Smelkov's avatar Kirill Smelkov

fixup! Dial: Catch NotPrimaryMaster & return custom error

Expect NotPrimaryMaster only if we are trying to connect to a master.
parent 7efe5d04
// Copyright (C) 2016-2021 Nexedi SA and Contributors. // Copyright (C) 2016-2023 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -147,22 +147,28 @@ func Dial(ctx context.Context, typ proto.NodeType, net xnet.Networker, addr stri ...@@ -147,22 +147,28 @@ func Dial(ctx context.Context, typ proto.NodeType, net xnet.Networker, addr stri
return err return err
} }
notPrimary := &proto.NotPrimaryMaster{} // besides AcceptIdentification and Error
// also expect NotPrimaryMaster if we are connecting to a master
nerr := &proto.Error{} nerr := &proto.Error{}
notPrimary := &proto.NotPrimaryMaster{}
respv := []proto.Msg{accept, nerr}
if typ == proto.MASTER {
respv = append(respv, notPrimary)
}
which, err := conn.Expect(nerr, notPrimary, accept) which, err := conn.Expect(respv...)
switch which { switch which {
case 0: case 0:
return nerr
case 1:
return notPrimary
case 2:
if accept.NodeType != typ { if accept.NodeType != typ {
// TODO send Error to peer? // TODO send Error to peer?
return fmt.Errorf("accepted, but peer is not %s (identifies as %s)", typ, accept.NodeType) return fmt.Errorf("accepted, but peer is not %s (identifies as %s)", typ, accept.NodeType)
} }
return nil return nil
case 1:
return nerr
case 2:
return notPrimary
} }
return err return 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