## P2PSP (Peer-to-Peer Straightforward Protocol)

July 19, 2019

Abstract

P2PSP (https://p2psp.github.io) is an application-layer multicast protocol that provides real-time broadcasting of media streams. Peers receive the stream generated by one or more media sources and share it, splitted in chunks. The peers are organized in so many unbounded-degree trees as peers there exist in the overlay. The trees are dynamic, and their topology try to minimize the transmission delay. The startup time experimented by the users depends mainly on the maximum expected size of the overlay. The QoS provided can be dynamically controlled, by adding and removing media sources. Polite churn does not genererate a loss of chunks. Unpolite (unexpected) churn produce a loss, but the number of lost chunks is bounded, and they are spread along the time and all peers. Selﬁsh peers are automatically isolated and rejected. All peers contribute with a I/O ratio of 1, but it is also possible to accomodate peers with connectivity restrictions (ﬁrewalls/NATs). If native IP multicast is avaliable, peers can use it. All these functionalities have been organized into a number of set of rules that can be enabled and disabled depending on the requirements.

### Notation

Cursive is used the ﬁrst time a P2PSP-related term/concept is introduced, and for key concepts or ideas.

### Introduction

P2PSP has a modular design organized in sets of rules, where each module is especialized in implementing diﬀerent functionalities.

### 1 LBS (Load Balancing Set)

Note: Finished but not implemented.

LBS is an standalone set of rules, and it is compatible with any other set.

P2PSP supposes that there is a collection of streams (usually, video) that are broadcasted in parallel.1 The streams are available at one or more2 streaming servers, and each stream has a diﬀerent Universal Resource Locator, usually expressed as a Web address with the structure:

http://server/mount_point

Notice that a server can be serving several channels.

P2PSP does not perform data-ﬂow control over the stream. The transmission bit-rate between P2PSP entities is controlled by the servers (Icecast servers, for example), which provides the stream to the P2PSP teams. Fig. 1 shows an example of a streaming overlay where several servers relay a set of channels generated by a set of source-clients, directly or through other servers. As can be seen, a listener (which usually plays the stream) can be replaced by a splitter, a P2PSP entity that sends the received stream (a single channel) to a set of P2PSP peers.

In a pure CDN system, users request the channels directly to the servers. Unfortunately, this simple procedure has a drawback: normally, users do not know the load nor the distance to the servers. This problem can be solved by using a load balancer. The listeners, which know the URL of the required channel, connects ﬁrst to a load balancer which redirects them (with an HTTP 302 code) to a suitable server.

This idea can be extended to minimize the response time of hybrid CDN/P2PSP structures. When a user (who knows an URL of the channel) runs a local peer, it provides to his peer the URL of the channel (the URL pointing to a server and a mount point). Then, the peer (as any other listener does) contacts a load balancer which in this case sends a list of splitters which are broadcasting the channel.3 Then, the peer tries to connect with all the splitters in parallel, and the ﬁrst establised connection determines the selected splitter (the rest of connections are closed). If only those splitters with space in their teams answer to the peer, this procedure should select the “nearest” splitter for the peer in terms of response time.

For the case of the incorporation of new splitters to the network, the procedure is similar. A new splitter (which is instantiated knowing an URL of a channel) contacts the load balancer which returns a list of servers and peers, which are serving the channel. Then, the splitter tries to connect with all of them in parallel, and the ﬁrst successfull connection is ﬁnally selected.4

Using the idea of the extended load balancer, when a player (listener) connects to it, if there is a local peer running in the same host or the same private network that the player, the balancer will redirect the player to the local peer.

Finally, it is compulsory that all the splitters associated to the same channel to generate exactly the same chunks (content and header). See Section 9 for more information.

### 2 DBS (Data Broadcasting Set)

Note: Finished and implemented.

DBS is the most basic set of rules. The rest of sets extends or modify its functionality.

 Parameter Meaning ${N}^{\ast }$ Maximum number of peers in a team $C$ Chunk size $B$ Buﬀer size, in chunks, in the peers ${B}^{\prime }$ Length of the list of the last ${B}^{\prime }$ peers served by the splitter $D$ Diameter of the ﬂooding tree ${L}^{\ast }$ Maximum allowed number of lost chunks $M$ Number of monitors $R$ Average bit-rate of the media Variable $N$ Number of peers in the team ${t}_{c}$ Chunk time ${t}_{r}$ Round time ${t}_{b}$ Buﬀering time ${t}_{p}$ Physical network latency ${t}_{s}$ Start-up time

Table 1: Nomenclature used in DBS.

DBS provides ALM of a media stream in an unicat environment. The media is sent by a streaming server (which is an external P2PSP entity), and received by a splitter(see Sec. 1) . The splitter divides the stream into a sequence of chunks of data, and relay them to a team of peers, following a round-robing schema. Each peer of a team gathers the chunks from the splitter and the rest of peers of the team, and sends them to at least one playerPeer should run even if no player(s) are connected to it. .

#### 2.1 Team deﬁnition and types of peers

For the splitter, a team is a set of one or more peers (referenced by their end-points) that share the same stream. By deﬁnition, in a team of size one (the corresponding splitter is considered out of the team that it feeds), the only peer is known as a monitor peer, and in a team with more than one peer, at least one of them must be a monitor. Monitors are instantiated by the overlay administrator to check diﬀerent aspects of the broadcasting, such as, the quality of the rendered video at the peers or the end-user latency.

The number of peers (normal peers and monitors) in a team has a maximum ${N}^{\ast }$ (see Tab. 1). This parameter has an impact on the latency of the protocol (see Sec. 2.4), and usually is deﬁned by the administrator of the overlay.

#### 2.2 Feeding the team

The splitter divides the stream into chunks of constant length $C$, and sends exclusively each chunk to a diﬀerent origin5 peer, using a round-robin schema. Chunks are enumerated to distinguish them, and this information is transmitted as a part of a chunk header.

We deﬁne a round as the process of transmitting $N$ diﬀerent chunks from the splitter to a team of $N\le {N}^{\ast }$ peers (therefore, all the peers of the team are origin of a diﬀerent chunk, in each round). For a team of size $N$, the round time can be estimated as

 ${t}_{r}=N{t}_{C}.$ (1)

Notice that ${t}_{r}$ is generally variable, and depends on the current number of peers in the team ($N$), and the chunk time

 ${t}_{c}=\frac{C}{R},$ (2)

which depends on the chunk size $C$ and the average bit-rate of the media stream $R$.

#### 2.3 Joining a team

After connecting with a splitter, incoming peers request (using a reliable communication) to the splitter the current list of peers in the team. To minimize the joining time, the peer sends a short $\left[\mathtt{hello}\right]$ message to each other peer of the team, in parallel with the reception of the list. When a peer of the team receives a $\left[\mathtt{hello}\right]$, it adds the sender of the message to the team list6 and to a table of peers called $\mathtt{forward}\left[\right]$ (see $\text{forward[]}$ in peer.py). If a peer ${P}_{i}$ has an entry $\mathtt{forward}\left[{P}_{j}\right]={P}_{k}$, then each chunk received by ${P}_{i}$ and originated at ${P}_{j}$ will be forwarded to ${P}_{k}$. When an incoming peer ${P}_{i}$ has received the list of peers, its forwarding table has been initialized to $\mathtt{forward}\left[{P}_{i}\right]=\left\{\text{team}\setminus {P}_{i}\right\}$. Notice that, as long as the forwarding table contains this information, all chunks received from the splitter will be forwarded to the rest of the team, directly (in one single hop). So, in absence of communication constraints, the team will be organized as a full-connected overlay (see Fig. 2a).

The splitter, in an inﬁnite loop: (1) listens to the incoming peers, (2) sends to them the list of peers of the team, and (3) includes the incoming peer to the list. Notice that only those peers that are in the list of peers of the splitter are considered to be in the team served by such splitter.

#### 2.4 Buﬀering chunks

In order to hide the jitter generated by the physical network and the protocol itself, peers need to store the received chunks in a buﬀer during a period of time, before sending them to a player. A chunk with number $x$ is inserted in the position $\left(x\phantom{\rule{1em}{0ex}}\mathit{mod}\phantom{\rule{1em}{0ex}}2B\right)$ of the buﬀer, where $B$ is the maximum number of chunks that the buﬀer stores. In a peer’s life, $B$ is a constant especiﬁed by the user, but it is not compulsory that all peers of a team use the same buﬀer size.

The buﬀer is implemented as a circular queue of $2B$ chunks, what is ﬁlled with up to $B$ chunks during the buﬀering time ${t}_{b}$, which is the main part of the start-up time that the users experiment. Chunks with a higher number (newer chunks) are inserted near of (depending on the order in which the chunks arrive to the peer) the head of the buﬀer. The (received) chunks pointed by the tail of the buﬀer ${p}_{p}$ (the playing pointer) are sent to the player. This action is carried out each time a new chunk is received7 . During the playing process, empty cells in the buﬀer (caused by the chunks that have not been received on time) are skipped until to ﬁnd the next cell with content.

#### 2.5 Buﬀering time estimation

The buﬀering-time, estimated by

 ${t}_{b}=B{t}_{c},$ (3)

determines how long the peers must wait for start playing the chunks. For real-time communications, ${t}_{b}$ should be as small as possible, and to achieve this we can reduce ${t}_{c}$ and $B$. Unfortunately, these reductions generate another drawbacks. On the one hand, the overhead of the header of the transport protocol is inversely proportional to ${t}_{c}$, and therefore, ${t}_{c}$ should be large enough to keep under control this overhead. On the other hand, if $B$ is too small (for example, if $B<{N}^{\ast }$) the peer will not have enought space to buﬀer all the chunks of a round, and due to the probability of receiving all the chunks in order is very small, some chunks will overwrite others before they can be played. This problem can also happen even if ${N}^{\ast }\le B<2{N}^{\ast }$, because the maximum jitter for a given peer (generated by DBS) that a chunk can experiment is the sum of the maximum jitter produced by the splitter for this peer, that can be ${N}^{\ast }$, and the maximum jitter produced by the team, that also can be ${N}^{\ast }$. Notice that this jitter is the same for the two extreme topologies of the overlay: (1) a full-connected mesh (Fig. 2a) or (2) a ring (Fig. 2b), and both topologies are possible in real scenarios. Therefore, users should select

 $B\ge 2{N}^{\ast }.$ (4)

Given a $N$ value, DBS peers may buﬀer a diﬀerent number of chunks that depends on the order in which chunks are received. If ${x}_{1}$ is the (number of the) ﬁrst received chunk (the ﬁrst chunk to be played), the buﬀering time ﬁnishes when a chunk with number equal or greater than ${x}_{1+B}$ is received.8 Lets analyze some interesting cases.

Lets suppose that the ﬁrst received chunk is ${x}_{1}$ and that the rest of chunks of the buﬀer of size $B$ are received, being the chunk ${x}_{1+B}$ the last one (this is the ideal scenario). In this case, the stream can be played without artifacts. Because the playing of the chunks starts after the buﬀering process, the start-up time experimented by users in the ideal case can be estimated by

 ${t}_{s}={t}_{b}+{t}_{p},$ (5)

being ${t}_{p}$ the latency generated by the physical layer.

Imagine now one of the worst possible scenarios, in which after receiving ${x}_{1}$ the chunk ${x}_{1+B}$ is received. In this case, the chunks ${x}_{2},\cdots {x}_{1+B-1}$ have been lost or delayed too much, but again (and considering that ${t}_{c}$ is a constant), the buﬀering-time is corresponds also with Eq. 3, because the chunk ${x}_{1+B}$ was generated $B$ chunk-times after ${x}_{1}$. Therefore, in this case the start-up-time can be also estimated by Eq. 5.

After considering these two extreme situations, we can deduce that the start-up-time does not depend on the loss chunk ratio during the buﬀering-time (always that this ratio is smaller than one), but only on $B$, ${t}_{c}$ and ${t}_{p}$. Notice that, as a rule of thumb, it holds that the larger the buﬀer size, the lower the probability of lossing chunks as a consecuence of a high $\Delta {t}_{p}$ (physical jitter).

#### 2.6 Chunk ﬂooding

DBS implements a push-based protocol. When a peer receives a chunk, it can be retransmitted to a large number of neighbors (depending on the number of diﬀerent destination peers in its forwarding table for the origin of the chunk). Therefore, even if the chunk rate is controlled by the streaming servers, some kind of ﬂow control must be performed by the peers in order to reduce network congestion while the chunks are ﬂooded.

(a) A full-connected overlay.

(b) A star-shaped overlay.

Figure 2: In a full-connected DBS team (see Subﬁg. (a)), all peers receive and send the same number of chunks. In a star-shaped DBS team (Subﬁg. (b)), ${P}_{1}$ should send all the chunks of the stream to the rest of the team, except those that the splitter has sent directly to them.

The congestion (in particular, the one caused by how DBS nodes use the physical links) may be avoided by means of a basic idea: only if I have received a chunk, I send (not necessary to the sender) a chunk (not necessary the received chunk). It is easy to see that, in a fully connected overlay (see Fig. 2a), this allows to control the data ﬂow. However, in more realistic scenarios, where the physical media imposes interconnexion constraints (such as those generated by ﬁrewalls and symmetric NATS), peers can not be directly “connected” with the rest the team, and therefore, if the splitter follows a pure round-robin strategy, some peers will send more chunks than they receive (as happens for example in Fig. 2b). In these scenarios, the simple idea of sending a chunk for each received one does not work.

Fortunately, the previous idea can be adapted to handle a variable connectivity degree (also called neighborhood degree) if each peer uses a table of lists, $\mathtt{pending}\left[\right]$, indexed by the neighbor’s end-points, where each list references the positions in the buﬀer of those chunks that must be transmited to the corresponding neighbor, the next time such neighbor is selected in the ﬂooding process. For example, if $\mathtt{pending}\left[{P}_{x}\right]=\left\{11,22\right\}$, chunks found at positions $11$ and $22$ of the buﬀer have to be sent to peer ${P}_{x}$.

Notice that using this procedure, more than one chunk can be sent to a neighbor in a transmission burst, which could congest the physical devices. However, except in very unbalanced overlays (as for example the shown in the Fig. 2b), the bursts are very short on average (only one chunk in most of cases). As an advantage, when a burst is produced, all the chunks of the burst travel between the two same hosts, which usually increases the performance of the layer-3 routing. Moreover, in this case, chunks could be grouped in one single packet, reducing the protocol overhead.

An example of the temporal evolution of a team using the ﬂooding algorithm has been described in the Figures 3, 4 and 5.

Note:

#### 2.7 Routes discovery and topology optimization

Chunks can be lost under bandwidth and buﬀering time constraints (a chunk is lost when it is time to send it to the player, i.e. when it is pointed by ${p}_{p}$, and the chunk has not been received). Because of that when a peer realizes that a chunk pointed by ${p}_{p}$ has been lost, nothing can be done to recover it, peers pre-fetch “potentially lost” chunks at the buﬀer position ${p}_{p}+{p}_{h}$, where ${p}_{h}\ge 0$ is the pre-feching horizon. Notice that if ${p}_{h}=0$, the pre-fetching is disabled and only those chunks that really are lost will be requested. On the contrary, the higher the ${p}_{h}$, the more agressive the pre-fetching.

For each (potentially) lost chunk with number $\text{lost_chunk_number}$, peers send a $\left[\mathtt{request}\phantom{\rule{1em}{0ex}}\text{lost_chunk_number}\right]$ message to a random peer of the team. When a peer ${P}_{i}$ receives such message from a ${P}_{j}$, ${P}_{i}$ adds ${P}_{j}$ to $\mathtt{forward}\left[{P}_{k}\right]$, where ${P}_{k}$ is the origin peer of the chunk stored in the position $\left(\text{lost_chunk_number}\phantom{\rule{1em}{0ex}}\mathit{mod}\phantom{\rule{1em}{0ex}}2B\right)$ of its buﬀer, this chunks has been received. Otherwise, the request is ignored. Notice that, although request messages are very short, they are an overhead.

When request messages are used, redundant routes can be created and therefore, some chunks could be received more than once. Obviously, this is also an overhead that must be minimized. To achieve this, the receiver of the prunning message counts the number of times that a origin peer has been pruned, and when this counters is higher than a threshold $T$ (the maximum number of generated duplicates), the corresponding entry in the $\text{forward}\left[\right]$ table is deleted.

Now, we can deﬁne more accurately the neighborhood degree (see Sec. 2.6) as the number of diﬀerent destination peers for each possible origin that a peer forwards. For example, if a peer ${P}_{i}$ forwards chunks from the origin ${P}_{i}$ to 10 neighbors, the neighborhood degree of ${P}_{i}$ for the origin ${P}_{i}$ is 10, and if the peer ${P}_{i}$ also forwards chunks from an origin ${P}_{j}$ to 5 neighbors, the neighborhood degree of ${P}_{i}$ for the origin ${P}_{j}$ is 5.

Considering the rules described before, the neighborhood degrees of peers can decrease or increase to optimize the topology of the overlay, by minimizing $\Delta {t}_{b}$. An increment in the degree for the origin of a requested chunk $\text{lost_chunk_number}$ in ${P}_{i}$ is produced when ${P}_{i}$ recives a $\left[\mathtt{request}\phantom{\rule{1em}{0ex}}\text{lost_chunk_number}\right]$ from a peer that is not a neighbor, yet. On the contrary, a decrement in the degree for the origin of a pruned chunk $\text{duplicate_chunk_index}$ in ${P}_{i}$ is produced when ${P}_{i}$ receives a $\left[\mathtt{prune}\phantom{\rule{1em}{0ex}}\text{duplicate_chunk_index}\right]$ from a neighbor peer, for that origin. In fact, the continued use of the requesting and prunning messages produce in a peer ${P}_{i}$ that the list $\text{forward}\left[{P}_{i}\right]$ gets shorter (smaller neighborhood degree) and new entries in the table $\text{forward}\left[\right]$ are created.

#### 2.8 Leaving a team

An outgoing peer must to: (1) say $\left[\mathtt{goodbye}\right]$ to the splitter and the neighbor peers (in this order), (2) relay any pending (received but yet not sent) chunks, and (3) wait for a $\left[\mathtt{goodbye}\right]$ from the splitter. In case of timeout9 , the leaving procedure is reset a number of times.

When a peer ${P}_{i}$ receives a $\left[\mathtt{goodbye}\right]$ from ${P}_{j}$, ${P}_{i}$ removes ${P}_{j}$ from all the lists (all the posible origins) of $\mathtt{forward}\left[\right]$ table. The splitter removes the outgoing peer from the list of peers as soon as the $\left[\mathtt{goodbye}\right]$ is received, to avoid sending chunks to it.

#### 2.9 Free-riding control at the splitter

The splitter remembers which chunk, of a list of the last ${B}^{\prime }$ transmitted chunks, was sent to each peer of the team. Notice that, in order to remember the chunk that was sent to each peer in each round, it must be hold that ${B}^{\prime }\ge N$. See $\text{destination_of_chunk}\left[\right]$ in splitter_dbs.py.

Monitor peers (which are trusted peers) complain to their splitter with a $\left[\mathtt{lost}\phantom{\rule{1em}{0ex}}\text{lost_chunk_number}\right]$ for each lost chunk. The splitter only considers these type of messages if they come from a monitor.

Note: This last functionality has not been implemented, at least, as it has been explained here. The forget() thread is controlled by a timer, not by a counter of rounds.

### 3 ACS (Adaptive Capacity Set)

Note: Unﬁnished. This set is incompatible with FCS (see Sec. 4).

ACS modiﬁes the functionality of DBS.

Basically, ACS relaxes the peer’s uploading requirements imposed by DBS. ACS is based on the idea of using the information that the splitter knows about the number of chunks that each peer has lost (see Sec. 2.9), to send to the more reliable peers a higher number of chunks. In other words, ACS adapts the round-time of each peer to its capacity, in such a way that the higher the capacity, the lower the round time.

ACS should be used if we want that some peers to put the uploading capacity than others cannot provide. A possible situation could be when we want to mix the CS and P2P models, sending more chunks from the contents provider’s hosts to the users’s peers, with the objective, for example, of incrementing the QoS. Because monitors should lost a minimum number of chunks (supposely the hosts of the contents provider should have enough capacity), the ratio of chunks emitted by the contents provider’s hosts can be controlled if a high enough number of monitor peers (the more monitors, the higher the ratio).

Notice that ACS only aﬀects the behavior of the splitter.

### 4 FCS (Free-riding Control Set)

Note: Finished but not implemented. This set is incompatible with ACS (see Sec 3).

FCS extends the functionality of DBS.

DBS does not imposes any control over the grade of solidarity of the peers. This means that selﬁsh peers (or simply peers with reduced connectivity) can stay in the team thanks to the generosity of the rest of peers, even if they never achive to deliver a chunk to any peer of the team. This set or rules preclude this possible behavior, by impossing a minimum degree of solidarity between neighbor peers.

To know the level of solidarity between neighbor peers, each peer uses a table of chunk debts, $\mathtt{debt}\left[\right]$. Every time a peer ${P}_{i}$ sends a chunk to ${P}_{j}$, ${P}_{i}$ increments $\mathtt{debt}\left[{P}_{j}\right]$, and decrements $\mathtt{debt}\left[{P}_{j}\right]$ when ${P}_{i}$ receives a chunk from ${P}_{j}$.

Using DBS, peers forward chunks to their neighbors using a simple round-robing scheduer) FCS modiﬁes this behavior:

1. The $\mathtt{pending}\left[\right]$ table is run in the order provided by $\mathtt{debt}\left[\right]$, selecting ﬁrst those entries with a smaller debts.
2. The run of $\mathtt{pending}\left[\right]$ is reset in each round (when a chunk is received from the splitter). This means that each round starts sending the pending chunks to those peers with a smaller debt.
3. If ${P}_{i}$ realises that $\mathtt{debt}\left[{P}_{j}\right]>{L}^{\ast }$, ${P}_{i}$ removes ${P}_{j}$ from $\mathtt{forward}\left[\forall {P}_{k}\in \left\{\text{team}\cup {P}_{i}\right\}\right]$ and from $\mathtt{pending}\left[\right]$. Notice that this action decreases the neighborhood degree of ${P}_{i}$ and, soon or later, of ${P}_{j}$ because of it will consider ${P}_{i}$ as unsupportive.
4. In DBS, request messages are sent selecting the destination peers at random. In FCS, request messages are sent to those peers with a higher debt. Thus, if the insolidarity is produced by a overlay topology imbalance (an extreme example is in Fig. 2b), badly connected peers peers could have the chance of mitigating this problem by forwarding more chunks to their neighbors.

Using FCS, supportive peers will be served ﬁrst, incrementing the QoE of the users of the corresponding peers. On the other hand, those peers with a higher chunk debt will tend to be unserved if no enough bandwidth is available. Notice that FCS is incompatible with ACS.

Note: The prioritized round-robin neighbor selection has not yet been implemented as it has been explained here. The $\text{debt}\left[\right]$ structure exists, but is used for a diﬀerent purporse.

### 5 IMS (Ip Multicast Set)

Note: Finished and implemented.

IMS modiﬁes the functionality of DBS.

IPM is available by default in LANs (Local Are Networks) and VLANs (Virtual LANs) [4], but not in the Internet [3]. IMS runs on the top of DBS and provides eﬃcient native IPM, where available.

All peers in the same LAN or VLAN have the same network address. When a joining peer ${P}_{i}$ receives the list of peers from its splitter, ﬁrst checks if there are neighbors in the same subnet. For all those peers, ${P}_{i}$ uses the IP address $\mathtt{224.0.0.1}$ (all systems on this subnet), (default) port $\mathtt{1234}$, to multicast (only) the chunks received from the splitter. Therefore, all peers in the same local network communicate using this multicast group address and port. The rest of external peers will be referenced using their public end-points.

### 6 TAS (Topology Adaptation Set)

Note: Unﬁnished.

In TAS, the splitter request to each peer of the team the list of neighbors (peers that send chunks directly, in one hop). This communication is reliable (TCP) and transmits the lists as a collection of end-points. The number of requests per round is limited by the available bandwidth in the overlay, and by the request-ratio deﬁned at the splitter. Obviously, the higher the ratio, a more accurate description of the real connectivity in the overlay will be obtained.

After knowing the connectivity degree of each peer, the slitter can adapt the round-robin scheduling of the origin peers by sending a number of chunks proportional to the inverse of the degree of the origin peer.

### 7 MRS (Massively-lost chunk Recovery Set)

Note: Finished but not implemented.

MRS extends DBS (or an extension of it) to retransmit massively-lost chunks. MRS should be implemented if error-prone communications are expected, specially if these channels are used by the splitter. MRS is based on the use of monitors (see Sec: 2.9). The idea is: the splitter will resend lost chunks to one or more the monitors when all monitors report their loss. To increase the probability of receiving on time the resent chunk (by normal peers), monitors halves the number of chunks in their buﬀers in relation to common peers. Notice that MRS only modiﬁes the behavior of the splitters and the monitors (normal peers does no need to implement LRS or its extensions).

### 8 NTS (NAT Traversal Set)

Note: Finished but not implemented.

Most of the peers run inside of “private” networks, i.e. behind NAT devices. NTS10 is an DBS extension which provides peer connectivity for some NAT conﬁgurations where DBS can not provide direct peer communication.11

Peers behind the same NAT will use the same external (also called “public”, because in most cases we have not nested NAT conﬁgurations) IP address of the NAT. Basically, there exist two diﬀerent types of NATs: (1) cone, and (2) symmetric. At the same time, NATs can implement diﬀerent ﬁltering strategies for the packets that comes from the external side: (a) no ﬁltering, (b) source IP ﬁltering, and (c) source end-point ﬁltering. Finally, NATs can use several port allocation algorithms, among which, the most frequent are: (i) port preservation and (ii) random port. Notice that in this discussion, only UDP transmissions will be considered.

#### 8.1 Traﬃc ﬁltering

Lets suppose a team in which, for the sake of simplicity, there is only one external (public) peer ${P}_{e}$, and that a new internal (private) peer ${P}_{i}$ has sent the sequence of [$\mathtt{hello}$]’s (see Sec 2.3). Lets denote ${P}_{i}$’s NAT as $A$. When no ﬁltering is used at all, $A$ forwards to ${P}_{i}$ any external packet that arrives to it (obviously, if it was sent to the entry in $A$’s translation table that was created during the transmission of the sequence of [$\mathtt{hello}$]’s), independently on the source end-points of the packets. In the case of source (IP) address ﬁltering, $A$ will forward the packets only if they come from ${P}_{e}$’s host. When source end-point ﬁltering is used, $A$ also checks the source port, i.e., that the packets were originated at ${P}_{e}$’s end-point.

#### 8.2 Cone VS symmetric

Cone NATs use the same external end-point for every packet that comes from the same internal end-point, independently on the destination of the packets (see Fig. 9). For the external peer ${P}_{e}$, the situation is identical to the case in which the NATed peer ${P}_{i}$ would be running in a public host.

Symmetric NATs use diﬀerent external end-points for diﬀerent packets that comes from the same internal end-point, when these packets have diﬀerent destination end-points (see Fig. ??). Thus, two diﬀerent external peers will see two diﬀerent public end-points of ${P}_{e}$.

#### 8.3 Port allocation

In the case of port preservation, if $X$:$Y$ is the private end-point (IP address:port) of a UDP packet, the NAT will use the public port $Y$, if available (notice that $Y$ cound have been assigned to a previous communcation). If $Y$ were unavailable, the NAT usually will assign the closer free port (this is called “sequentially port allocation”), usually by increasing the port value, although this behavior has not been standarized at all.

When random port allocation is implemented, the public port will be assigned at random. Notice that, even in SN-PPA conﬁgurations, in most of the real situations (where peers must compete with the rest of processes that use the network for the same NAT resources,) some kind of randomization should be always expected during a the port assignment.

#### 8.4 NAT type analysis

An incoming peer ${P}_{i}$ can determine its NAT behavior using the following steps:

1. Let ${A}_{0},{A}_{1},\cdots \phantom{\rule{0.3em}{0ex}},{A}_{M}\right\}$ the public ports used by peer ${P}_{i}$, whose NAT is $A$, to send the [$\mathtt{hello}$] UDP packets towards the splitter $S$ and the $M$ monitor peers of the team, in this order. This data is known by ${P}_{i}$ after receiving the acknowledgment of each [$\mathtt{hello}$]. Compute
 ${\Delta }_{k}={\mathsf{A}}_{k}-{\mathsf{A}}_{k-1}$ (6)

for $k=1,2,\cdots \phantom{\rule{0.3em}{0ex}},M$, the port distances gathered by ${P}_{i}$.

2. Determine a port step
 (7)

where GCD is the Greatest Common Divisor operator.

3. If $\Delta =0$ ($A$ is using the same external port for communicating ${P}_{i}$ with the rest of peers of the team) then ${P}_{i}$ is behind a cone NAT. Notice that public (not NATed) peers will be considered as being using this type of NAT, also.
4. If $\Delta >0$ ($A$ is using a diﬀerent external port for each external peer) then ${P}_{i}$ is behind a symmetric NAT. In this case:
1. If
 ${\Delta }_{1}={\Delta }_{2}=\cdots ={\Delta }_{m}$ (8)

then $A$ is using sequentially port allocation.

2. If
 $\Delta =\underset{m\to \infty }{lim}\mathrm{GCD}\left({\Delta }_{1},\cdots \phantom{\rule{0.3em}{0ex}},{\Delta }_{m}\right)=1.$ (9)

then $A$ is using random port allocation.

#### 8.5 (Theoretical) NAT traversal performance of DBS

 Peer1/2 CN CN-AF CN-EF SN-PPA SN-RPA CN DBS DBS DBS DBS DBS CN-AF DBS DBS DBS NTS - CN-EF DBS DBS DBS NTS - SN-PPA DBS NTS NTS NTS - SN-RPA DBS - - - -

Table 2: NAT traversal success for diﬀerent NAT typical combinations. CN-NF (also known by “full cone NAT”) stands for Cone NAT (without packet ﬁltering). CN-AF (also known as “restricted cone NAT”) stands for Cone NAT with source Address Filtering. CN-EF (also known by “port restricted cone NAT”) stands for Cone NAT source End-point Filtering. SN-PPA stands for Symmetric NAT Port Preservation Allocation, and no packet ﬁltering has been considered. SN-RPA stands for Symmetric NAT Random Port Allocation, and no packet ﬁltering has been used.

Figure 12: Timeline of an (ideal) NTS interaction between two peers ${P}_{1}$ and ${P}_{2}$ which are behind symmetric NATs.

Table 2 shows the theoretical traversal success of DBS (or an extension of it) for diﬀerent NAT type combinations. Peer1 represents to a peer already joined to the team, and Peer2 to an incoming peer. The entries labeled with “DBS” are those that will be handled by DBS, out-of-the-box. An explanation of why the DBS handshake works for such conﬁgurations is shown in Fig. 10. Notice that source end-point ﬁltering has been used in this example, although a similar results should be obtained for simple source address ﬁltering. On the other hand, the combinations labeled with “-” or “NTS” will not work with DBS (see Fig.11). In fact, only the “NTS” entries should work, in general, with NTS, depending on the port prediction algorithm and the number of tries.

Fig. 12 shows an example of an NTS (NAT traversal) success. When the new NATed peers, ${P}_{1}$ and ${P}_{2}$, arrive at the team, the following events happen:

• $M$ requests to join the team (the joining request is not shown in the ﬁgure for brevity) and $S$ sends to $M$ an empty list of peers. At this moment, $M$ has joined the team.
• ${P}_{1}$ requests $S$ to join through an external port ${A}_{0}$ (again, this message is not shown). $S$ sends to ${P}_{1}$ the list of peers. This list contains only the endpoint of $M$.
• NAT $A$ relays towards ${P}_{1}$ the previuos message.
• ${P}_{1}$ answers $\left[\mathtt{hello}M\right]$ to $M$.
• $A$ relays the previous message, which is received by $M$. Due to $A$ is a symmetric NAT, a new source port ${A}_{1}$ is used for this message.
• $M$ sends $\left[\mathtt{ack}M\right]$ towards $\left(A,{A}_{1}\right)$.
• The previous message is relayed by $A$. Simultaneously, $M$ informs to $S$ that ${P}_{1}$ has communicated with it, using the external endpoint $\left(A,{A}_{1}\right)$.
• $S$ acknowledges the reception of the previous message.
• ${P}_{2}$ requests to join the team (not shown) and $S$ sends to it the current list of peers, which contains the endpoint of $M$ and the tuple $\left(\left(A,{A}_{0}\right),{\Delta }_{A},#{P}_{2}\right)$ (the external endpoint used by ${P}_{1}$ to communicate with $S$, the maximum port step in NAT $A$, ${\Delta }_{A}$ measured by $S$ for ${P}_{1}$ thoroughtout its incorporation to the team, and the index of ${P}_{2}$, $#{P}_{2}$, in the list of peers). Using this information, ${P}_{2}$ will perform the port prediction for the external port that $\mathsc{𝒜}$ will assign to ${P}_{1}$ when it be communicating with ${P}_{2}$. This prediction is the list of ports ${Z}_{#{P}_{1}}=$ get_guessed_ports($#{P}_{2}$,${A}_{0}$,${\Delta }_{A}$) is populated by ${P}_{2}$ using the Algorithm ??.
• $B$ retransmits the previous message.
• ${P}_{2}$ sends a $\left[\mathtt{hello}M\right]$ towards $M$.
• $B$ retransmits the previous message, which arrives to $M$, and ${P}_{2}$ sends a $\left[\mathtt{hello}\left(A,{A}_{2}\right)\right]$ towards $\left(A,{A}_{2}\right)$, which has been computed in the Step 08.
• The previous message arrives to $\left(A,{A}_{2}\right)$ (which is correct), but $A$ discards this packet because still there is not a working entry in its translation table for the key $\left(\left(B,{B}_{2}\right),{A}_{2}\right)$.
• $M$ acknowledges the $\left[\mathtt{hello}M\right]$, which arrived in the Step 11.
• The $\left[\mathtt{ack}M\right]$ message is received by ${P}_{2}$ and $M$ informs to $S$ that ${P}_{2}$ is also using the port ${B}_{1}$ (this information is used to compute the maximum port step ${\Delta }_{B}$ in NAT $B$, measured for ${P}_{2}$ thoroughout its incorporation.
• $S$ acknowledges the previous reception.
• $S$ sends to ${P}_{1}$ the message $\left[\left(B,{B}_{0}\right),{\Delta }_{B},{S}^{\prime }\right]$ (external end-point used by ${P}_{2}$ to talk with $S$, port step measured for ${P}_{2}$ and a new temporaly listenning port ${S}^{\prime }$ at node $S$). The tuple $\left(\left(B,{B}_{0}\right),{\Delta }_{B}\right)$ allows ${P}_{1}$ to predict which external port (${B}_{2}$) will use $\mathrm{NAT}B$ when ${P}_{2}$ sends a packet to ${P}_{1}$. The extra socket bound by $S$ to ${S}^{\prime }$ will be used to update the external port that ${P}_{1}$ is currently using to communicate with the rest of peers of the team.
• ${P}_{1}$ receives the previous message.
• ${P}_{1}$ says $\left[\mathtt{hello}{P}_{2}\right]$ to EEP $\left(\mathrm{NAT}B,{B}_{2}\right)$.
• ${P}_{1}$ says $\left[\mathtt{hello}S\right]$ to EEP $\left(S,{S}^{\prime }\right)$.
• $\mathrm{NAT}B$ relays the message $\left[\mathtt{hello}{P}_{2}\right]$ towards ${P}_{2}$ and $\left[\mathtt{hello}S\right]$ is received by $S$ (which updates the external port for ${P}_{1}$). Notice that at this moment, ${P}_{2}$ knows that ${P}_{1}$ is able to send data to it.
• Both, $S$ and ${P}_{2}$ acknowledges the $\left[\mathtt{hello}\right]$ messages.
• $\left[\mathtt{ack}S\right]$ is received by ${P}_{1}$, $\left[\mathtt{ack}{P}_{2}\right]$ is received by $\mathrm{NAT}A$ and the timer assigned to the message $\left[\mathtt{hello}{P}_{1}\right]$ sent in Step 11 timeouts and this message is re-sent.
• ${P}_{1}$ receives $\left[\mathtt{ack}{P}_{2}\right]$ and $\mathrm{NAT}A$ receives $\left[\mathtt{hello}{P}_{1}\right]$.
• $\left[\mathtt{hello}{P}_{1}\right]$ is delivered to ${P}_{1}$. At this moment, ${P}_{1}$ knows that ${P}_{2}$ is able to send data to it.
• ${P}_{1}$ acknowledges the previous $\left[\mathtt{hello}{P}_{1}\right]$.
• $\left[\mathtt{ack}{P}_{1}\right]$ arrives to $\mathrm{NAT}B$.
• $\left[\mathtt{ack}{P}_{1}\right]$ arrives to ${P}_{2}$.
• ${P}_{1}$ and ${P}_{2}$ annouce to the $S$ the source port used by the other peer.
• This information is received by the $S$, which updates the external port information for ${P}_{1}$ and ${P}_{2}$.

Summarizing, NTS can provide connectivity for those peers that are behind port-preservation symmetric NATs with sequential port allocation.

#### 8.6 A port prediction algorithm (Max’s proposal)

When both peers, Peer1 and Peer2, are behind symmetric NATs, both must predict the port that the NAT of the interlocutor peer will use to send the packets towards it. And obviously, this must be performed by each already incorporated peer that is behind a symmetric NAT.

The list of predicted ports $Z$ that a a peer ${P}_{x}$ performs is determined by:

 $\begin{array}{ccc}\hfill Z& \hfill =\hfill & {A}_{0}+x+\left\{s\in \left\{0,1,\cdots \phantom{\rule{0.3em}{0ex}},N∕2-1\right\}\right\};\hfill \\ \hfill Z& \hfill +=\hfill & {A}_{0}+\left(x+\left\{s\in \left\{0,1,\cdots \phantom{\rule{0.3em}{0ex}},N-1\right\}\right\}\right)\cdot \Delta .\hfill \end{array}$ (10)

where “$+=$” denotes the concatenation of lists and $N$ is the number of guessed ports, ${A}_{0}$ is the ﬁrst external port (the port used to communicate with $S$) assigned to the incoming peer and $\Delta$ is the (maximum) port step measured for the incoming peer’s NAT.

### 9 MCS (Multi-Channel Set)

Note: Unﬁnished.

When using MDC [1], SVC [2], or for emulating the CS model, it can be interesting for peers to belong to more than one team. To implement MCS, peers must replicate the P2PSP modules (DBS at least) for each team (channel), except the buﬀer.

The use of MDC is trivial: the higher the number received descriptions (channels), even partially, the higher the quality of the playback. However, when transmitting SVC media, peers should prioritize the reception of the most important layers.

When a peer belongs to more than one team, and the teams broadcast exactly the same stream (the same chunks and headers), it could move between teams seamless (without losts of signal).

A pure CS service could be provided if the corresponding splitter announces one empty team and sends each chunk so many times as teams (with one peer/team) there are.

### 10 CIS (Content Integrity Set)

Note: Unﬁnished.

A variety of techniques to ﬁght pollution in P2P live streaming systems are available in the literature, including hash-based signature and data encryption techniques.

### Acronyms

ALM
Application Layer Multicast. 13
DBS
Data Broadcasting Set of rules. 13
URL
Universal Resource Locator. 8

### Glossary

Buﬀering time
The time required receive at least two chunks separated by the buﬀer size. 18
Chunk
A piece of stream. 13
Chunk time
The time required to play a chunk. 16
Joining time
The time required by a peer to receive the list of peers of the team from the splitter. 16
Media
Data expresing information usually interpreted by humans. 13, 70
Monitor
A trusted and reliable peer of a team. 13
Neigborhood degree
The number of neighbors (peers) to which a chunk is forwarded. 24, 37, 38, 44
Origin
The ﬁrst peer in the path that each chunk follows between the splitter and the team. 15
Player
An application that is able to reproduce a media stream. 13
Round
The process of sending a (usually diﬀerent) chunk from the splitter to all the peers of the team. 15
Round time
The time required to complete a round. 16, 41
Server
A process running on the Internet that is able to send data upon requests. 8, 13
Splitter
P2PSP entity responsible for splitting the media into chunks and sending the to the team. 13
Start-up time
The time required by a peer to start playing the stream. 18, 21
Stream
A sequence of data that is consumed while it is received. 8, 13
Team
The set of peers in an P2PSP overlay. 13
Unicast
A point-to-point communication. 13

### References

[1]   Pierpaolo Baccichet, Jeonghun Noh, Eric Setton, and Bernd Girod. Content-aware p2p video streaming with low latency. In Multimedia and Expo, 2007 IEEE International Conference on, pages 400–403. IEEE, 2007.

[2]   Xiaowen Chu, Kaiyong Zhao, Zongpeng Li, and Anirban Mahanti. Auction-based on-demand p2p min-cost media streaming with network coding. IEEE Transactions on Parallel and Distributed Systems, 20(12):1816–1829, 2009.

[3]   Douglas E. Comer. Internetworking with TCP/IP. Principles, Protocols, and Architectures (4th Edition), volume 1. Prentice Hall, 2000.

[4]   Lior Shabtay and Benny Rodrig. Ip multicast in vlan environment, April 12 2011. US Patent 7,924,837.