Pass handsake errors to caller.
This commit is contained in:
parent
828544cb2f
commit
935335f1a5
1 changed files with 12 additions and 9 deletions
21
sockets.go
21
sockets.go
|
@ -639,7 +639,13 @@ func BtcdConnect(certificates []byte, reply chan error) {
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
BtcdHandler(btcdws, done)
|
BtcdHandler(btcdws, done)
|
||||||
BtcdHandshake(btcdws)
|
|
||||||
|
if err := BtcdHandshake(btcdws); err != nil {
|
||||||
|
log.Errorf("%v", err)
|
||||||
|
reply <- ErrConnRefused
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
<-done
|
<-done
|
||||||
reply <- ErrConnLost
|
reply <- ErrConnLost
|
||||||
}
|
}
|
||||||
|
@ -671,14 +677,12 @@ func resendUnminedTxs() {
|
||||||
// settings between the two processes (such as running on different
|
// settings between the two processes (such as running on different
|
||||||
// Bitcoin networks). If the sanity checks pass, all wallets are set to
|
// Bitcoin networks). If the sanity checks pass, all wallets are set to
|
||||||
// be tracked against chain notifications from this btcd connection.
|
// be tracked against chain notifications from this btcd connection.
|
||||||
func BtcdHandshake(ws *websocket.Conn) {
|
func BtcdHandshake(ws *websocket.Conn) error {
|
||||||
n := <-NewJSONID
|
n := <-NewJSONID
|
||||||
cmd := btcws.NewGetCurrentNetCmd(fmt.Sprintf("btcwallet(%v)", n))
|
cmd := btcws.NewGetCurrentNetCmd(fmt.Sprintf("btcwallet(%v)", n))
|
||||||
mcmd, err := cmd.MarshalJSON()
|
mcmd, err := cmd.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Cannot complete btcd handshake: %v", err)
|
return fmt.Errorf("cannot complete btcd handshake: %v", err)
|
||||||
ws.Close()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
correctNetwork := make(chan bool)
|
correctNetwork := make(chan bool)
|
||||||
|
@ -688,7 +692,6 @@ func BtcdHandshake(ws *websocket.Conn) {
|
||||||
fnet, ok := result.(float64)
|
fnet, ok := result.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("btcd handshake: result is not a number")
|
log.Error("btcd handshake: result is not a number")
|
||||||
ws.Close()
|
|
||||||
correctNetwork <- false
|
correctNetwork <- false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -710,9 +713,7 @@ func BtcdHandshake(ws *websocket.Conn) {
|
||||||
btcdMsgs <- mcmd
|
btcdMsgs <- mcmd
|
||||||
|
|
||||||
if !<-correctNetwork {
|
if !<-correctNetwork {
|
||||||
log.Error("btcd and btcwallet running on different Bitcoin networks")
|
return errors.New("btcd and btcwallet running on different Bitcoin networks")
|
||||||
ws.Close()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(jrick): Check that there was not any reorgs done
|
// TODO(jrick): Check that there was not any reorgs done
|
||||||
|
@ -736,4 +737,6 @@ func BtcdHandshake(ws *websocket.Conn) {
|
||||||
NotifyNewBlockChainHeight(frontendNotificationMaster, bs.Height)
|
NotifyNewBlockChainHeight(frontendNotificationMaster, bs.Height)
|
||||||
NotifyBalances(frontendNotificationMaster)
|
NotifyBalances(frontendNotificationMaster)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue