Commit fb47abdd authored by David Stainton's avatar David Stainton

Async send instead of blocking

parent 361636bf
Pipeline #940 passed with stage
in 7 minutes and 23 seconds
......@@ -68,9 +68,11 @@ func TestClientConnect(t *testing.T) {
// send a message
t.Logf("desc.Provider: %s", desc.Provider)
_, err = s.SendUnreliableMessage(desc.Name, desc.Provider, []byte("hello!"))
t.Logf("Sent unreliable message to loop service")
mesgID, err := s.SendUnreliableMessage(desc.Name, desc.Provider, []byte("hello!"))
require.NoError(err)
_, err = s.WaitForReply(mesgID)
require.NoError(err)
t.Logf("Sent unreliable message to loop service")
c.Shutdown()
t.Logf("Shutdown requested")
......@@ -160,9 +162,11 @@ func TestDecoyClient(t *testing.T) {
wg.Add(1)
go func() {
t.Logf("SendUnreliableMessage()")
_, err := s.SendUnreliableMessage(desc.Name, desc.Provider, []byte("hello!"))
wg.Done()
mesgID, err := s.SendUnreliableMessage(desc.Name, desc.Provider, []byte("hello!"))
require.NoError(err)
_, err = s.WaitForReply(mesgID)
require.NoError(err)
wg.Done()
}()
}
wg.Wait()
......
......@@ -30,7 +30,7 @@ type MessageID *[cConstants.MessageIDLength]byte
// received SURB replies.
type Message struct {
// ID is the message identifier
ID *[cConstants.MessageIDLength]byte
ID MessageID
// Recipient is the message recipient
Recipient string
......
......@@ -73,7 +73,7 @@ func (s *Session) waitForSent(id MessageID) error {
}
// WaitForReply blocks until a reply is received.
func (s *Session) waitForReply(id MessageID) ([]byte, error) {
func (s *Session) WaitForReply(id MessageID) ([]byte, error) {
s.log.Debugf("WaitForReply message ID: %x\n", *id)
err := s.waitForSent(id)
if err != nil {
......@@ -259,8 +259,8 @@ func (s *Session) composeMessage(recipient, provider string, message []byte) (*M
return &msg, nil
}
// SendUnreliableMessage sends message without any automatic retransmissions.
func (s *Session) SendUnreliableMessage(recipient, provider string, message []byte) ([]byte, error) {
// SendUnreliableMessage asynchronously sends message without any automatic retransmissions.
func (s *Session) SendUnreliableMessage(recipient, provider string, message []byte) (MessageID, error) {
msg, err := s.composeMessage(recipient, provider, message)
if err != nil {
return nil, err
......@@ -276,5 +276,5 @@ func (s *Session) SendUnreliableMessage(recipient, provider string, message []by
if err != nil {
return nil, err
}
return s.waitForReply(msg.ID)
return msg.ID, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment