refactor: LocalConnection.CheckFatal be gone!
use Shutdown instead, which is in the Connection interface, thus further reducing dependency on LocalConnection.
This commit is contained in:
1 parent
9a27299562
commit
99525ebf85
5 files changed
+16
-23
No files matched your search
+4
-13
@@ -149,17 +149,6 @@ func (conn *LocalConnection) Established() bool {
|
||||
return conn.established
|
||||
}
|
||||
|
||||
// Called by the forwarder processes in a few places (including
|
||||
// crypto), but the connection TCP receiver process, and by the local
|
||||
// peer actor process. Do not call this from the connection's actor
|
||||
// process itself.
|
||||
func (conn *LocalConnection) CheckFatal(err error) error {
|
||||
if err != nil {
|
||||
conn.Shutdown(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Called by forwarder processes, read in Forward (by sniffer and udp
|
||||
// listener process in router).
|
||||
func (conn *LocalConnection) setEffectivePMTU(pmtu int) {
|
||||
@@ -538,7 +527,8 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
|
||||
for {
|
||||
var msg []byte
|
||||
conn.extendReadDeadline()
|
||||
if conn.CheckFatal(decoder.Decode(&msg)) != nil {
|
||||
if err = decoder.Decode(&msg); err != nil {
|
||||
conn.Shutdown(err)
|
||||
return
|
||||
}
|
||||
msg, err = receiver.Decode(msg)
|
||||
@@ -597,7 +587,8 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
|
||||
conn.SendProtocolMsg(ProtocolMsg{ProtocolFetchAll, nil})
|
||||
continue
|
||||
}
|
||||
if conn.CheckFatal(err) != nil {
|
||||
if err != nil {
|
||||
conn.Shutdown(err)
|
||||
return
|
||||
}
|
||||
if len(newUpdate) != 0 {
|
||||
|
||||
+4
-2
@@ -204,7 +204,8 @@ func (ne *NaClEncryptor) Bytes() []byte {
|
||||
nonce := ne.nonce
|
||||
if nonce == nil {
|
||||
freshNonce, encodedNonce, err := EncodeNonce(ne.df)
|
||||
if err = ne.conn.CheckFatal(err); err != nil {
|
||||
if err != nil {
|
||||
ne.conn.Shutdown(err)
|
||||
return []byte{}
|
||||
}
|
||||
ne.conn.SendProtocolMsg(ProtocolMsg{ProtocolNonce, encodedNonce})
|
||||
@@ -222,7 +223,8 @@ func (ne *NaClEncryptor) Bytes() []byte {
|
||||
ne.nonce = <-ne.nonceChan
|
||||
} else if offset == 1<<14 { // half way through range, send new nonce
|
||||
nonce, encodedNonce, err := EncodeNonce(ne.df)
|
||||
if err = ne.conn.CheckFatal(err); err != nil {
|
||||
if err != nil {
|
||||
ne.conn.Shutdown(err)
|
||||
return []byte{}
|
||||
}
|
||||
ne.nonceChan <- nonce
|
||||
|
||||
+1
-1
@@ -349,7 +349,7 @@ func (fwd *Forwarder) flush() {
|
||||
} else if PosixError(err) == syscall.ENOBUFS {
|
||||
// TODO handle this better
|
||||
} else {
|
||||
fwd.conn.CheckFatal(err)
|
||||
fwd.conn.Shutdown(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,21 +192,21 @@ func (peer *LocalPeer) handleAddConnection(conn *LocalConnection) {
|
||||
dupConnLocal := dupConn.(*LocalConnection)
|
||||
switch conn.BreakTie(dupConnLocal) {
|
||||
case TieBreakWon:
|
||||
dupConnLocal.CheckFatal(dupErr)
|
||||
dupConn.Shutdown(dupErr)
|
||||
peer.handleDeleteConnection(dupConnLocal)
|
||||
case TieBreakLost:
|
||||
conn.CheckFatal(dupErr)
|
||||
conn.Shutdown(dupErr)
|
||||
return
|
||||
case TieBreakTied:
|
||||
// oh good grief. Sod it, just kill both of them.
|
||||
conn.CheckFatal(dupErr)
|
||||
dupConnLocal.CheckFatal(dupErr)
|
||||
conn.Shutdown(dupErr)
|
||||
dupConn.Shutdown(dupErr)
|
||||
peer.handleDeleteConnection(dupConnLocal)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := peer.checkConnectionLimit(); err != nil {
|
||||
conn.CheckFatal(err)
|
||||
conn.Shutdown(err)
|
||||
return
|
||||
}
|
||||
peer.addConnection(conn)
|
||||
@@ -239,7 +239,7 @@ func (peer *LocalPeer) handleConnectionEstablished(conn *LocalConnection) {
|
||||
log.Fatal("Peer informed of active connection where peer is not the source of connection")
|
||||
}
|
||||
if dupConn, found := peer.connections[conn.Remote().Name]; !found || conn != dupConn {
|
||||
conn.CheckFatal(fmt.Errorf("Cannot set unknown connection active"))
|
||||
conn.Shutdown(fmt.Errorf("Cannot set unknown connection active"))
|
||||
return
|
||||
}
|
||||
peer.connectionEstablished(conn)
|
||||
|
||||
+1
-1
@@ -252,7 +252,7 @@ func (router *Router) udpReader(conn *net.UDPConn, po PacketSink) {
|
||||
err = relayConn.Decryptor.IterateFrames(handleUDPPacket, udpPacket)
|
||||
if pde, ok := err.(PacketDecodingError); ok {
|
||||
if pde.Fatal {
|
||||
relayConn.CheckFatal(pde)
|
||||
relayConn.Shutdown(pde)
|
||||
} else {
|
||||
relayConn.log(pde.Error())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user