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:
Matthias Radestock committed 2015-01-21 21:23:59 +00:00
1 parent 9a27299562
commit 99525ebf85
5 files changed
+16 -23

No files matched your search

+4 -13
View File
@@ -149,17 +149,6 @@ func (conn *LocalConnection) Established() bool {
return conn.established 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 // Called by forwarder processes, read in Forward (by sniffer and udp
// listener process in router). // listener process in router).
func (conn *LocalConnection) setEffectivePMTU(pmtu int) { func (conn *LocalConnection) setEffectivePMTU(pmtu int) {
@@ -538,7 +527,8 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
for { for {
var msg []byte var msg []byte
conn.extendReadDeadline() conn.extendReadDeadline()
if conn.CheckFatal(decoder.Decode(&msg)) != nil { if err = decoder.Decode(&msg); err != nil {
conn.Shutdown(err)
return return
} }
msg, err = receiver.Decode(msg) msg, err = receiver.Decode(msg)
@@ -597,7 +587,8 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
conn.SendProtocolMsg(ProtocolMsg{ProtocolFetchAll, nil}) conn.SendProtocolMsg(ProtocolMsg{ProtocolFetchAll, nil})
continue continue
} }
if conn.CheckFatal(err) != nil { if err != nil {
conn.Shutdown(err)
return return
} }
if len(newUpdate) != 0 { if len(newUpdate) != 0 {
+4 -2
View File
@@ -204,7 +204,8 @@ func (ne *NaClEncryptor) Bytes() []byte {
nonce := ne.nonce nonce := ne.nonce
if nonce == nil { if nonce == nil {
freshNonce, encodedNonce, err := EncodeNonce(ne.df) freshNonce, encodedNonce, err := EncodeNonce(ne.df)
if err = ne.conn.CheckFatal(err); err != nil { if err != nil {
ne.conn.Shutdown(err)
return []byte{} return []byte{}
} }
ne.conn.SendProtocolMsg(ProtocolMsg{ProtocolNonce, encodedNonce}) ne.conn.SendProtocolMsg(ProtocolMsg{ProtocolNonce, encodedNonce})
@@ -222,7 +223,8 @@ func (ne *NaClEncryptor) Bytes() []byte {
ne.nonce = <-ne.nonceChan ne.nonce = <-ne.nonceChan
} else if offset == 1<<14 { // half way through range, send new nonce } else if offset == 1<<14 { // half way through range, send new nonce
nonce, encodedNonce, err := EncodeNonce(ne.df) nonce, encodedNonce, err := EncodeNonce(ne.df)
if err = ne.conn.CheckFatal(err); err != nil { if err != nil {
ne.conn.Shutdown(err)
return []byte{} return []byte{}
} }
ne.nonceChan <- nonce ne.nonceChan <- nonce
+1 -1
View File
@@ -349,7 +349,7 @@ func (fwd *Forwarder) flush() {
} else if PosixError(err) == syscall.ENOBUFS { } else if PosixError(err) == syscall.ENOBUFS {
// TODO handle this better // TODO handle this better
} else { } else {
fwd.conn.CheckFatal(err) fwd.conn.Shutdown(err)
} }
} }
} }
+6 -6
View File
@@ -192,21 +192,21 @@ func (peer *LocalPeer) handleAddConnection(conn *LocalConnection) {
dupConnLocal := dupConn.(*LocalConnection) dupConnLocal := dupConn.(*LocalConnection)
switch conn.BreakTie(dupConnLocal) { switch conn.BreakTie(dupConnLocal) {
case TieBreakWon: case TieBreakWon:
dupConnLocal.CheckFatal(dupErr) dupConn.Shutdown(dupErr)
peer.handleDeleteConnection(dupConnLocal) peer.handleDeleteConnection(dupConnLocal)
case TieBreakLost: case TieBreakLost:
conn.CheckFatal(dupErr) conn.Shutdown(dupErr)
return return
case TieBreakTied: case TieBreakTied:
// oh good grief. Sod it, just kill both of them. // oh good grief. Sod it, just kill both of them.
conn.CheckFatal(dupErr) conn.Shutdown(dupErr)
dupConnLocal.CheckFatal(dupErr) dupConn.Shutdown(dupErr)
peer.handleDeleteConnection(dupConnLocal) peer.handleDeleteConnection(dupConnLocal)
return return
} }
} }
if err := peer.checkConnectionLimit(); err != nil { if err := peer.checkConnectionLimit(); err != nil {
conn.CheckFatal(err) conn.Shutdown(err)
return return
} }
peer.addConnection(conn) 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") 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 { 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 return
} }
peer.connectionEstablished(conn) peer.connectionEstablished(conn)
+1 -1
View File
@@ -252,7 +252,7 @@ func (router *Router) udpReader(conn *net.UDPConn, po PacketSink) {
err = relayConn.Decryptor.IterateFrames(handleUDPPacket, udpPacket) err = relayConn.Decryptor.IterateFrames(handleUDPPacket, udpPacket)
if pde, ok := err.(PacketDecodingError); ok { if pde, ok := err.(PacketDecodingError); ok {
if pde.Fatal { if pde.Fatal {
relayConn.CheckFatal(pde) relayConn.Shutdown(pde)
} else { } else {
relayConn.log(pde.Error()) relayConn.log(pde.Error())
} }