Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
TCPCL: Increase Client's verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
oxzi committed Oct 10, 2019
1 parent 893b146 commit 8f27155
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cla/tcpcl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func (client *TCPCLClient) String() string {
var b strings.Builder

fmt.Fprintf(&b, "TCPCL(")
fmt.Fprintf(&b, "peer=%v, ", client.conn.RemoteAddr())
if client.conn != nil {
fmt.Fprintf(&b, "peer=%v, ", client.conn.RemoteAddr())
} else {
fmt.Fprintf(&b, "peer=NONE, ")
}
fmt.Fprintf(&b, "active peer=%t", client.active)
fmt.Fprintf(&b, ")")

Expand Down Expand Up @@ -131,6 +135,7 @@ func (client *TCPCLClient) Start() (err error, retry bool) {
if client.conn == nil {
if conn, connErr := net.DialTimeout("tcp", client.address, time.Second); connErr != nil {
err = connErr
retry = true
return
} else {
client.conn = conn
Expand All @@ -157,15 +162,17 @@ func (client *TCPCLClient) handleConnection() {
atomic.AddInt32(&client.handleCounter, -1)
}()

var rw = bufio.NewReadWriter(bufio.NewReader(client.conn), bufio.NewWriter(client.conn))
// var rw = bufio.NewReadWriter(bufio.NewReader(client.conn), bufio.NewWriter(client.conn))
var r = bufio.NewReader(client.conn)
var w = bufio.NewWriter(client.conn)

for {
select {
case msg := <-client.msgsOut:
if err := msg.Marshal(rw); err != nil {
if err := msg.Marshal(w); err != nil {
client.log().WithError(err).WithField("msg", msg).Error("Sending message errored")
return
} else if err := rw.Flush(); err != nil {
} else if err := w.Flush(); err != nil {
client.log().WithError(err).WithField("msg", msg).Error("Flushing errored")
return
} else {
Expand All @@ -187,7 +194,7 @@ func (client *TCPCLClient) handleConnection() {
return
}

if msg, err := ReadMessage(rw); err == nil {
if msg, err := ReadMessage(r); err == nil {
client.log().WithField("msg", msg).Debug("Received message")
client.msgsIn <- msg
} else if err == io.EOF {
Expand Down Expand Up @@ -223,6 +230,8 @@ func (client *TCPCLClient) handleState() {
stateHandler = client.handleSessInit
case client.state.IsEstablished():
stateHandler = client.handleEstablished
default:
client.log().WithField("state", client.state).Fatal("Illegal state")
}

if err := stateHandler(); err != nil {
Expand All @@ -246,7 +255,10 @@ func (client *TCPCLClient) handleState() {
var sessTerm = NewSessionTerminationMessage(0, TerminationUnknown)
client.msgsOut <- &sessTerm

client.reportChan <- cla.NewConvergencePeerDisappeared(client, client.peerEndpointID)
emptyEndpoint := bundle.EndpointID{}
if client.endpointID != emptyEndpoint {
client.reportChan <- cla.NewConvergencePeerDisappeared(client, client.peerEndpointID)
}

return
}
Expand Down

0 comments on commit 8f27155

Please sign in to comment.