Searching for files and waiting for responses

Searching for files and waiting for responses

by Morten Borup Petersen -
Number of replies: 5

Short question on AddSearchMessages. In the documentation, it is stated that:

AddSearchMessage initiates a file search by broadcasting a search request for the given keywords and waits for responses

In a network with no matching searches, no responses would be received. On the other hand, "responses" is also fairly ambiguous since (i would assume) the "found 2 files" criteria of budget=0 searches does not apply when budget != 0 - and as such, how many responses would be enough to return from the search call?

Both of these naturally lead to the assumption that we probably should implement a timeout period for executing the search. Would this be correct?

- Morten

In reply to Morten Borup Petersen

Re: Searching for files and waiting for responses

by Kirill Nikitin -

Hi,

I would say that timeouts are not necessary for completion of the homework (unless you really want to implement them). The reason is that in both cases your operations are bounded (thanks to the hoplimit and the cap on increasing the budget), and in the case of the zero budget, you know that you need to resend every second unless there are enough responses. So you could decouple the state of a search and the process of sending out requests. When budget != 0, you can check the progress when processing search replies (in terms of the client, you could return results whenever you get new ones) but you do not need to explicitly "stop" the search, at least for the sake of the homework.

I hope this helps!

Kirill

In reply to Kirill Nikitin

Re: Searching for files and waiting for responses

by Morten Borup Petersen -

Thank you. However, i am still a bit confused;

Take, for instance, TestGossiper_Search_Query_Low_Budget. No search replies will be sent to node A since there are no matches in any node (no files are indexed). As such, in this case, there is no clear indicator for the progress of As search.

I noticed this when i had initially created my search as non-blocking - but passed the test - due to the 1 second timeouts (gossiper_test.go l. 475) between each search transmission, which allows for the propagation of the search request to all of the nodes.

- Morten

In reply to Morten Borup Petersen

Re: Searching for files and waiting for responses

by Kirill Nikitin -

It is true that we do not define progress for search. In the case of a budgeted query, you might not get a response at all, as in TestGossiper_Search_Query_Low_Budget. But it is somewhat difficult to know what timeout it should be even if this approach is taken because it is unclear how much time it takes for a query to propagate in a decentralized network. We know this in the tests because we define the network structure but it is not obvious in general.

Your search implementation surely should not be blocking. A simple way to do this is by decoupling status of your searches from message sending. Of course, without timeouts, the state will be growing indefinitely since you do not know when to remove budgeted searches from there. But it is ok for this homework.

Kirill

In reply to Kirill Nikitin

Re: Searching for files and waiting for responses

by Dorian Ros -

So if I understood correctly, the method AddSearchMessage should return pretty much immediately ?

Also do we notify the NewMessageCallback only when we have total match or at every reply message ?

Thanks!

In reply to Dorian Ros

Re: Searching for files and waiting for responses

by Kirill Nikitin -

Hi,

That depends on your implementation. But even if you keep waiting, it should be in a routine (so you don't block), so indeed AddSearchMessage should return. When you wait in a routine, you should have concrete rules when to exit it (e.g., when threshold of two matches is achieved), otherwise your gossiper might end up consuming memory until it crashes.

Regarding the callback, you are free to do it as you prefer, the only restriction is that the callback expects a gossip packet so you might need to craft one. We have added this piece mostly for you to be able to use the GUI, and there is no test checking it, so it is not a requirement.

Kirill