go-gtp
go-gtp copied to clipboard
Catch Echo Responses
Hi @wmnsk, I see that when we send any of the messages we can use session.WaitMessage(sequence, GtpTimeout) to wait for the response for this specific message. That function works because that message is received on a specific queue for that session
However, when we send and EchoRequest, there is no session concept, so we can't use WaitMessate function.
I see that you have solved that on func Dial where you manually handle the echo response. But that can be done because 'Dial` function has access to the private methods on the connection.
Maybe I am missing the function, but is there any way to wait for an EchoResponse similar to waitMessage?
Thanks
Hi,
As you see Echo does not belong to a session, as it’s a “path management” message.
To do something with Echo, I suggest adding a customized handler to the Conn A goroutine that sends a request and the one the handler works can communicate with channels. So, high-level overview of the implementation is like;
- Sender: Send a request and keep the peer address as “in-flight”.
- Handler: Look up the in-flight request by peer, notify that to sender via a channel.
- Sender: Remove it when the “in-flight” request has the response, or alert(or cleanup sessions with that peer etc.) that when it’s timed out or the restart counter is incremented.
Hope this helps.
Let me know if you have any questions/problems.
Sorry for some reason I wasn't subscribed to the repo when you sent the first message and I totally missed it.
I used a simplified version of your aproach: right now I just have a channel that is being used by the handler to drop the result. I am not checking the in-flight request (which is not good). So far is not a problem since we just have one cliant and one server. But will have to rework it to use your aproach.
By the way, does the default echoResponse handler do anything on the background I may be missing? Or is just as dumb as it seems?
func handleEchoResponse(c *Conn, senderAddr net.Addr, msg message.Message) error {
// this should never happen, as the type should have been assured by
// msgHandlerMap before this function is called.
if _, ok := msg.(*message.EchoResponse); !ok {
return &UnexpectedTypeError{Msg: msg}
}
// do nothing.
return nil
}
Thanks!