Skip to content
Snippets Groups Projects
Unverified Commit 7d67039f authored by capossele's avatar capossele
Browse files

:zap: Improve analysis-server

parent b3d49d26
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ require (
github.com/golang/protobuf v1.3.5
github.com/google/go-cmp v0.4.0
github.com/gorilla/websocket v1.4.1
github.com/iotaledger/hive.go v0.0.0-20200617164933-c48b4401b814
github.com/iotaledger/hive.go v0.0.0-20200618111525-99e5fb050f12
github.com/iotaledger/iota.go v1.0.0-beta.14
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0
......
......@@ -64,6 +64,7 @@ func runFPCLiveFeed() {
analysis.Events.FPCHeartbeat.Detach(onFPCHeartbeatReceived)
cleanUpTicker.Stop()
log.Info("Stopping Analysis[FPCUpdater] ... done")
return
case <-cleanUpTicker.C:
log.Info("Cleaning up Finalized Conflicts ...")
recordedConflicts.cleanUp()
......
package server
import (
"io"
"net"
"strconv"
"strings"
"time"
"github.com/iotaledger/goshimmer/packages/shutdown"
......@@ -82,31 +84,29 @@ func run(_ *node.Plugin) {
// HandleConnection handles the given connection.
func HandleConnection(conn *network.ManagedConnection) {
conn.Events.Error.Attach(events.NewClosure(func(err error) {
log.Warn(err)
_ = conn.Close()
}))
err := conn.SetReadTimeout(IdleTimeout)
if err != nil {
log.Error(err)
log.Warnw("Error setting read timeout; closing connection", "err", err)
_ = conn.Close()
return
}
onReceiveData := events.NewClosure(func(data []byte) {
// process incoming data in protocol.Receive()
_, err := prot.Read(data)
if err != nil {
log.Warnf("invalid message received: %s", err)
log.Warnw("Invalid message received; closing connection", "err", err)
_ = conn.Close()
}
})
conn.Events.ReceiveData.Attach(onReceiveData)
// starts the protocol and reads from its connection
go func() {
buffer := make([]byte, 2048)
_, _ = conn.Read(buffer)
_, err := conn.Read(buffer)
if err != nil && err != io.EOF && !strings.Contains(err.Error(), "use of closed network connection") {
log.Warnw("Read error", "err", err)
}
// always close the connection when we've stopped reading from it
_ = conn.Close()
}()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment