Skip to content

Commit

Permalink
Convinience debug statements and proper handling of router probing wh…
Browse files Browse the repository at this point in the history
…en no router is connected
  • Loading branch information
jakob22r committed Jan 6, 2025
1 parent 3f6e125 commit 3890ae2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions edgerouter/edgerouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func NewEdgeRouter(listeningAddr string, mrn string, outgoingChannel chan *mmtp.
}

func (er *EdgeRouter) connectMMTPToRouter(ctx context.Context, wg *sync.WaitGroup) error {
log.Debugf("Own mrn is %v", er.ownMrn)

connect := &mmtp.MmtpMessage{
MsgType: mmtp.MsgType_PROTOCOL_MESSAGE,
Uuid: uuid.NewString(),
Expand Down Expand Up @@ -277,20 +279,25 @@ func (er *EdgeRouter) TryConnectRouter(ctx context.Context, wg *sync.WaitGroup)
return
}
}
if err := er.routerWs.CloseNow(); err != nil {
log.Warn(err)
if er.routerWs != nil {
if err := er.routerWs.CloseNow(); err != nil {
log.Warn(err)
}
}

//Make sure old connection is completely cleaned up

//Runs until a router has been found
log.Info("Probing for a router connection")
for {
log.Debugf("Attempt connect to %v", *er.routerAddr)
select {
case <-ctx.Done():
return
case <-time.After(5 * time.Second):
routerWs, _, err := websocket.Dial(ctx, *er.routerAddr, &websocket.DialOptions{HTTPClient: er.httpClient, CompressionMode: websocket.CompressionContextTakeover})
if err != nil {
log.Debugf("Could not connect to router: %v", err)
continue
}
er.routerWs = routerWs
Expand Down

0 comments on commit 3890ae2

Please sign in to comment.