Stop Method

Stop Method

by Francesco Intoci -
Number of replies: 6

Hello,

I am having some troubles trying to figure out how the Gossipers should work in respect to the Stop method. I want to be sure that I got the correct sense of the method.

Let's suppose that there are 3 gossipers g1, g2 and g3. g2 calls the Stop method. Hence he has to send a StopMessage to all his known peers and after that he can close the UDP socket he had opened for communication. Is that right?

Moreover should g1 and g3 keep track of the status of g2? If g1 knows g2 and g3 and he wants to send a GossipMessage, he will have to send it just to g3?

Thanks in advance!

In reply to Francesco Intoci

Re: Stop Method

by Cristina Basescu -

Hi,

Very good question to ask!

The behavior is, actually, much simpler than that. A gossiper's stop method gracefully stops *only* that gossiper, i.e., the gossiper closes all connections, cleans up resources etc. The actions are entirely local. It does *NOT* send any message to other gossipers to inform them of the departure.

What you are suggesting would be a "Leave" method, where a gossiper leaving the network informs the others, so that they could potentially take other actions. For the time being, you are not required to implement such a method.

Cristina


In reply to Cristina Basescu

Re: Stop Method

by Francesco Intoci -
Hello,
Thank you for your reply! I still don't understand why there is a stopMsg constant defined, then. Moreover in the Stop () description it is stated that the gossiper should send a stopMsg to the listener. Should we ignore that for now?
In reply to Francesco Intoci

Re: Stop Method

by Cristina Basescu -

The logic is that the gossiper should finish processing the messages received *before* its Stop method is called. That's why "Stop" sends a message to the gossiper's listener, which identifies the "Stop" message by comparing it to the "stopMsg" constant.

Does that make sense?

Cristina

In reply to Cristina Basescu

Re: Stop Method

by Francesco Intoci -
Maybe I got it. So that should be the correct flow of operations:
1-go g.Run()
Gossiper g starts listening opening a UDP connection. In the Run method I would do something like "keep listening and process messages until stopMsg is received" in a for loop
2-Gossipers start exchanging messages
3- g.Stop()
g has to sent to itself(to its listener) the stopMsg. This is processed in the Run method that will end the loop and return. After sending the stopMsg, in the Stop() method there would be something like net Close(g.Listener).

Is that correct?
In reply to Francesco Intoci

Re: Stop Method

by Cristina Basescu -

That's exactly it.

Perhaps in the future, refrain from posting on the forum detailed step-by-step, pseudocode-like description of methods. If you need to do that, please use the course's e-mail address.