gossipy.flow_control module#
Module contents#
- class gossipy.flow_control.GeneralizedTokenAccount(C, A)#
Bases:
gossipy.flow_control.SimpleTokenAccount
Generalized token account.
Implements a generalized simple token account strategy with a reactive function that is able to increase the number of messages sent when the number of tokens is high. To this end, the proactive function is the same as in
SimpleTokenAccount
while the reactive function is defined as []:\(\operatorname{REACTIVE}(a, u)= \begin{cases}\lfloor(A-1+a) / A\rfloor & \text { if } u\\ \lfloor(A-1+a) /(2 A)\rfloor & \text { otherwise }\end{cases}\)
where \(u\) is the account balance, \(C\) is the capacity of the token account, and \(A\) is the reactivity of the token account.
- Parameters
- reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.
- class gossipy.flow_control.PurelyProactiveTokenAccount#
Bases:
gossipy.flow_control.TokenAccount
Purely proactive token account.
This is a special case of the token account framework and it essentially implements a standard push gossip algorithm.
- proactive()#
Method that along with the
reactive
method defines the token account strategy.- Returns
The probability of a token being consumed.
- Return type
- reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.
- class gossipy.flow_control.PurelyReactiveTokenAccount(k=1)#
Bases:
gossipy.flow_control.TokenAccount
Purely reactive token account.
Naive reactive token account variants where every message received triggers message sending immediately.
- Parameters
k (int, default=1) – The number of messages to send in case of reaction.
- proactive()#
Method that along with the
reactive
method defines the token account strategy.- Returns
The probability of a token being consumed.
- Return type
- reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.
- class gossipy.flow_control.RandomizedTokenAccount(C, A)#
Bases:
gossipy.flow_control.GeneralizedTokenAccount
This token account strategy implements a more fine-grained handling of proactive messages. In fact, the proactive function returns 1 when the balance is at least the capacity (as always) but it adds some proactive behavior even when this is not the case: the returned value is linear starting from A − 1 until C. The starting point of this linear segment is A − 1 because if the balance is less than A then the reactive function will be able to send less than one messages on average:
\(\operatorname{PROACTIVE}(a)= \begin{cases}0 & \text { if } a<A-1 \\ \frac{a-A+1}{C-A+1} & \text { if } a \in[A-1, C] \\ 1 & \text { otherwise. }\end{cases}\)
Instad, the reactive function is:
\(\operatorname{REACTIVE}(a, u)= \begin{cases} \text{randRound}(a / A) & \text { if } u \\ 0 & \text { otherwise }\end{cases}\)
where the only difference with the
GeneralizedTokenAccount
is that the rounding is performed randomly.- Parameters
- proactive()#
Method that along with the
reactive
method defines the token account strategy.- Returns
The probability of a token being consumed.
- Return type
- reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.
- class gossipy.flow_control.SimpleTokenAccount(C=1)#
Bases:
gossipy.flow_control.TokenAccount
Simple token account.
Implements a “standard” token account strategy where the node will proactively send a message if it has at the number of tokens are at least equal to the capacity. It is also reactive iff the node has at least one token.
- Parameters
C (int, default=1) – The capacity of the token account.
- proactive()#
Method that along with the
reactive
method defines the token account strategy.- Returns
The probability of a token being consumed.
- Return type
- reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.
- class gossipy.flow_control.TokenAccount#
Bases:
abc.ABC
Abstract class representing a generic token account.
The token account framework has been firstly proposed in [].
- add(n=1)#
Increases the number of tokens by
n
.
- abstract proactive()#
Method that along with the
reactive
method defines the token account strategy.- Returns
The probability of a token being consumed.
- Return type
- abstract reactive(utility)#
Method that along with the
proactive
method defines the token account strategy.It returns the number of messages that the node will send as a reaction to an incoming message, as a function of the account balance and the usefulness (i.e.,
utility
) of the received message.