P2PSP (Peer-to-Peer Straightforward Protocol)

The P2PSP team

May 18, 2019

Abstract

P2PSP (https://p2psp.github.io) is an application-layer protocol that provides real-time broadcasting of media streams on the Internet. Peers collaborate to diseminate the stream that is generated by a single source, generating a controlled latency and protocol overhead. P2PSP overlays (teams) are push-based (topology-driven) dynamic meshes. The chunks of data are forwarded without explicit requests, using a set of dynamic routes, that except in the case of losing chunks, show a maximum bounded latency, defined by the overlay users.

Notation

Cursive is used the first 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 different functionalities.

Contents

1 LBS (Load Balancing Set)
2 DBS (Data Broadcasting Set)
 2.1 Team definition and types of peers
 2.2 Feeding the team
 2.3 Joining a team
 2.4 Buffering chunks
 2.5 Chunk flooding
 2.6 Overlay organization
 2.7 Leaving a team
 2.8 Free-riding control
3 IMS (Ip Multicast Set)
4 FCS (Free-riding Control Set)
5 TAS (Topology Adaptation Set)
6 MRS (Massively-lost chunk Recovery Set)
7 ACS (Adaptive Capacity Set)
8 NTS (NAT Traversal Set)
 8.1 Traffic filtering
 8.2 Cone VS symmetric
 8.3 Port allocation
 8.4 NAT type analysis
 8.5 (Theoretical) NAT traversal performance of DBS
 8.6 A port prediction algorithm (Max’s proposal)
9 MCS (Multi-Channel Set)
10 CIS (Content Integrity Set)

1 LBS (Load Balancing Set)



Figure 1: A possible data-flow in an hybrid CDN(Icecast)/P2PSP network. S represents a splitter and Pi the i-th peer.

P2PSP supposes that there is a collection of channels that are broadcasted in parallel.1 The channels are available at one or more2 streaming servers, and each channel has a different URL (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-flow 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 first 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 first 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 first successfull connection is finally 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)


Parameter Meaning


B Buffer size in chunks
C Chunk size
L Maximum allowed number of lost chunks
M Number of monitors
N Maximum number of peers in a team

Table 1: Nomenclature used in DBS.

DBS provides ALM [2] of a media stream in unicast environments [5]. The media is sent by a streaming server, and received by a splitter (see Sec. 1). The splitter divides the stream into a sequence of chunks of data, and relay them to its team using a round-robing schema, where it can be up to N peers (see Tab. 1). Each peer gathers the chunks from the splitter and the rest of peers of the team, and sends them to at least one player5 .

2.1 Team definition and types of peers

A team is a set of one or more peers that share the same stream. By definition, in a team of size one (the corresponding splitter is considered out of its team), the only peer is known as a monitor peer. In a team with more than one peer, at least one of them must be a monitor peer. Monitors are instantiated by the team administrator to monitorize different aspects of the broadcasting, such as, the expected quality of the rendered video at the peers.

2.2 Feeding the team

The splitter divides the stream into chunks of constant length C (see Tab. 1), and sends exclusively each chunk to a different origin peer6 , using a round-robin schema. Chunks are enumerated to distinguish them, and this information is transmitted as a part of a chunk header.

We define a round as the process of transmitting N N (see Tab. 1) different chunks from the splitter to a team of N peers. Therefore, for a team of size N, the round-time is N chunk-times. Notice that the round-time is generally variable, and depends on the current number of peers in the team (N), the chunk size (C, see Tab. 1), and the average bit-rate of the media stream.

The splitter remembers which chunk, of a list of the last B (see Tab. 1) 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, B N. See destination_of_chunk[] in splitter_dbs.py.

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 [hello] message to each peer of the team, in parallel with the reception of the list. When a peer of the team receives a [hello], it adds the sender of the message to a table of peers called forward[] (see forward[] in peer.py). If a peer Pi has an entry forward[Pj] = Pk, then each chunk received by Pi and originated at Pj will be forwarded to Pk.

The splitter, in an infinite loop: 1) listens to the incoming peers, 2) sends the list of peers in the team, and 3) adds 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 of such splitter.

Note: See destination_of_chunk[] in peer_dbs.py.

2.4 Buffering 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 buffer during a period of time before sending them to a player. A chunk with number x is inserted in the position (xmod2B) of the buffer, where B(see Tab. 1) is the maximum number of chunks that the buffer will store. In a peer’s life, B is a constant, but it is not compulsory that all peers of the same team use the same B value.

The buffer is implemented as a circular queue of 2B chunks, which is filled up to only B chunks during the buffering time (which is the main part of the start-up time that the users experiment). Chunks with a higher number (newer chunks) are inserted in the head of the buffer. The chunk pointed by the tail of the buffer is sent to the player, if there is a chunk in that cell of the buffer. This action is carried out each time a new chunk is received.

The buffering time determines how much time the peers must wait for start playing the chunks. Considering that the chunks can be lost in transit or delayed more than B times of chunk, randomly, it is difficult to determine, a priori, the optimal buffering time. In the current implementation of P2PSP, peers buffer a variable number of chunks that depends on the order in which chunks are received. If x1 is the (index of the) first received chunk (the first chunk to be played), the buffering time finishes when the chunk x1 + B is received.7

2.5 Chunk flooding

DBS implements a content-unaware push-based protocol, and when a peer receives a chunk, it can be retransmitted to a large number of neighbors. Even by controlling the chunk rate in the servers, some kind of flow control must be performed in order to reduce network congestion while peers’s flooding.

Congestion may be avoided by means of a basic idea: if I have received a chunk, I should send a chunk. It is easy to see that, in a fully connected overlay, this allows to control the data flow. However, in more realistic scenarios, peers can be “connected” with a variable number of neighbors and therefore, if the splitter follows a pure round-robin strategy, some peers can send more chunks that they receive.

The previous idea can be adapted to handle a variable connectivity degree. Each peer uses a table of lists, pending[], indexed by the neighbor end-points, where each list stores the positions in the buffer of those chunks that must be transmited to the corresponding neighbor, the next time such neighbor be selected in the flooding process. Thus, if for example pending[Px] = {11,22}, chunks found at positions 11 and 22 of the buffer have to be sent to peer Px (when the round-robin scheduler used by the peer selects Px). The current scheduler used by the peers selects a different neighbor, using a round-robin scheme, for each new received chunk. An example of the temporal evolution of a team has been described in the Figures 2, 3, ...



Figure 2: A team has been created with a single monitor M0 ([hello] messages are not shown). Chunks with numbers 0 and 1 (the time t is measured in chunks-time) have been transmitted from the splitter S to M0. F and P represents the forward[] and the pending[] structures, respectively. The chunks stored in the buffer are shown under the entity.



Figure 3: At t2, peer P1 joins the team (the [hello]’s are not shown). In M0, F = {M0 : [P1]} because when M0 receives the [hello] from P1, M0 is the origin peer for all chunks received from S and P1 is its neighbor. P1 includes an entry P1 : [M0] in its forwarding table because M0 is in the list of peers received from the splitter. After that, when the chunk number 2 arrives to M0 from S, an entry P1 : 2 is created in P{} for that chunk, and this entry is deleted when the chunk 2 is sent to P1.



Figure 4: P2 joins the team. M0 and P1 includes P2 in their forwarding tables. The chunk 3 is received by P1 which decides to send it to P2. Chunk 3 remains as pending to be sent to M0 when the next chunk is received by P1.



Figure 5: Chunk 4 is received by P2 which relays it to P1, what relays chunk 3 to M0.



Figure 6: Chunk 5 is received by M0 which relays it to P2.

Note:



















An example of the flooding with congestion control algorithm has been show in the Figs. 2, ...

2.6 Overlay organization

Chunks can be lost.8 A chunk is considered as lost when it is time to send it to the player and the chunk has not been received. In this situation, for each lost chunk, the peer sends a [requestlost_chunk_number] to a randomly selected peer of the team. When a peer Px receives a [requestlost_chunk_number] from Py, Px adds Py to forward[Po], where Po is the origin peer of the chunk stored in the position lost_chunk_numbermod2B of its buffer.

In this situation, it can happens that some peers request redundant paths between an origin peer and itself, and therefore, some chunks could be received more than once. If this case, for each duplicate chunk, a peer Pi should send a [pruneduplicate_chunk_number] message to those neighbors that have sent to it the duplicate chunk. Neighbors receiving such message from peer Pi should remove the Pi from forward[Po], where Po is the origin peer of the duplicate chunk.

2.7 Leaving a team

An outgoing peer must to: (1) say [goodbye] 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 [goodbye] from the splitter. In case of timeout, the leaving procedure is reset a number of times.

When a peer of the team receives a [goodbye], removes the sender from its forward table.

The splitter removes the outgoing peer from the list of peers as soon as the [goodbye] is received.

2.8 Free-riding control

In each team there are a set of monitors (trusted peers whose behavior is predictable and that are only known by the splitter), which complain to their splitter with a [lostlost_chunk_number] for each lost chunk. The splitter only considers these type of messages if they come from a monitor.

If a peer Po accumulates more than L losts in R rounds, Po is removed from the splitter’s list of peers. All peers do the same, but in this case they also remove the selfish neighbors from the forward and pending tables.

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 IMS (Ip Multicast Set)

IPM is available by default in LANs (Local Are Network)s and VLANs (Virtual LANs) [6], but not in the Internet [4]. IMS runs on the top of DBS and provides efficient native IPM, where available.

The idea of IMS is simple: all peers in the same LAN or VLAN have the same network address. When a joining peer Pi receives the list of peers from its splitter, first checks if there are neighbors in the same subnet. For all those peers, Pi uses the IP address 224.0.0.1 (all systems on this subnet), (default) port 1234, to multicast (only) the chunks received from the splitter. Therefore, all peers in the same local network communicate using this IPM group address and port. The rest of external peers will be referenced using their public end-points.

4 FCS (Free-riding Control Set)

DBS does not imposes any control over the grade of solidarity of the peers. This means that selfish peers (or simply peers with reduced connectivity as a consecuence, for example, of NAT issues) can stay in the team thanks to the generosity of the rest of peers. If this is unnaceptable, this set of rules try to that all the peers of the team to share the same number of chunks that they receive.

To know the level of solidarity between neighbor peers, each peer implements a table of chunk debts, debt[]. Every time Pk sends a chunk to Pl, Pk runs debt[Pl] = debt[Pl] + 1, and Pl runs debt[Pk] = debt[Pk]2. So, peers increment the insolidarity measurement incrementally and decreases it exponentially towards zero. This respond to the idea of that, if a peer keeps sending chunks to their neighbors, it has doing its best in retransmitting the chunks it must forward.

With the debt[] information, peers modify the way the neighbor are selected during the flooding procedure. Now, the pending[] list is sorted by debts (those peers with a lower debt will appear in the first positions of pending[]), and when a peer receives a chunk from the splitter, the run over the pending[] list will be reset. In this way, supportive peers will be served first, incrementing the QoE of the corresponding users. On the other hand, those peers with a higher chunk debt will tend to be unserved if no enough bandwidth is available.

The second mechanism to increase the grade of solidarity is to send the [requestlost_chunk_number] to those peers with a higher debt. So, if the insolidarity is produced by a overlay topology imbalance, badly connected peers peers can mitigate this problem forwarding more chunks to their neighbors.

Note: The prioritized round-robin neighbor selection has not yet been implemented as it has been explained here. The debt[] structure exists, but is used for a different purporse.

5 TAS (Topology Adaptation Set)

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 defined 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.

6 MRS (Massively-lost chunk Recovery Set)

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.8). 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 buffers in relation to common peers. Notice that MRS only modifies the behavior of the splitters and the monitors (normal peers does no need to implement LRS or its extensions).

7 ACS (Adaptive Capacity Set)

ACS relaxes the peer’s upload requirements imposed by DBS. It should be used in if it is known that some peers can provide the capacity than others cannot, or when we want to mix the CS and P2P models, sending more chunks from the splitter to one or more monitors controlled by the contents provider.

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.8), to send to those more reliable peers a higher number of chunks than to the others. In other words, ACS adapts the round-time of each peer to its capacity.

Notice that ACS only affects the behavior of the splitter.

8 NTS (NAT Traversal Set)

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

Peers behind the same NAT will use the same external (also called “public”, because in most cases we have not nested NAT configurations) IP address of the NAT. Basically, there exist two different types of NATs: (1) cone, and (2) symmetric. At the same time, NATs can implement different filtering strategies for the packets that comes from the external side: (a) no filtering, (b) source IP filtering, and (c) source end-point filtering. 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 Traffic filtering

Lets suppose a team in which, for the sake of simplicity, there is only one external (public) peer Pe, and that a new internal (private) peer Pi has sent the sequence of [hello]’s (see Sec 2.3). Lets denote Pi’s NAT as A. When no filtering is used at all, A forwards to Pi 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 [hello]’s), independently on the source end-points of the packets. In the case of source (IP) address filtering, A will forward the packets only if they come from Pe’s host. When source end-point filtering is used, A also checks the source port, i.e., that the packets were originated at Pe’s end-point.



Figure 7: Cone NAT port allocation.



Figure 8: Symmetric NAT port allocation.

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. 8). For the external peer Pe, the situation is identical to the case in which the NATed peer Pi would be running in a public host.

Symmetric NATs use different external end-points for different packets that comes from the same internal end-point, when these packets have different destination end-points (see Fig. ??). Thus, two different external peers will see two different public end-points of Pe.

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 configurations, 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 Pi can determine its NAT behavior using the following steps:

  1. Let A0,A1,,AM} the public ports used by peer Pi, whose NAT is A, to send the [hello] UDP packets towards the splitter S and the M monitor peers of the team, in this order. This data is known by Pi after receiving the acknowledgment of each [hello]. Compute
    Δk = Ak Ak1 (1)

    for k = 1,2,,M, the port distances gathered by Pi.

  2. Determine a port step
    Δ = 0, if i,Δi = 0 GCD(Δ1,,Δm), otherwise (2)

    where GCD is the Greatest Common Divisor operator.

  3. If Δ = 0 (A is using the same external port for communicating Pi with the rest of peers of the team) then Pi is behind a cone NAT. Notice that public (not NATed) peers will be considered as being using this type of NAT, also.
  4. If Δ > 0 (A is using a different external port for each external peer) then Pi is behind a symmetric NAT. In this case:
    1. If
      Δ1 = Δ2 = = Δm (3)

      then A is using sequentially port allocation.

    2. If
      Δ = limmGCD(Δ1,,Δm) = 1. (4)

      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 different NAT typical combinations. CN-NF (also known by “full cone NAT”) stands for Cone NAT (without packet filtering). 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 filtering has been considered. SN-RPA stands for Symmetric NAT Random Port Allocation, and no packet filtering has been used.



Figure 9: An example that shows how it is possible to establish a connection with DBS when two peers P1 and P2 that are behind cone NATs.



Figure 10: An example that shows why its is impossible to establish a connection with DBS when two peers P1 and P2 that are behind symmetric NATs.



Figure 11: Timeline of an (ideal) NTS interaction between two peers P1 and P2 which are behind symmetric NATs.

Table 2 shows the theoretical traversal success of DBS (or an extension of it) for different 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 configurations is shown in Fig. 9. Notice that source end-point filtering has been used in this example, although a similar results should be obtained for simple source address filtering. On the other hand, the combinations labeled with “-” or “NTS” will not work with DBS (see Fig.10). In fact, only the “NTS” entries should work, in general, with NTS, depending on the port prediction algorithm and the number of tries.

Fig. 11 shows an example of an NTS (NAT traversal) success. When the new NATed peers, P1 and P2, arrive at the team, the following events happen:

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 Px performs is determined by:

Z = A0 + x + {s {0,1,,N2 1}}; Z + = A0 + (x + {s {0,1,,N 1}}) Δ. (5)

where “+ =” denotes the concatenation of lists and N is the number of guessed ports, A0 is the first external port (the port used to communicate with S) assigned to the incoming peer and Δ is the (maximum) port step measured for the incoming peer’s NAT.

9 MCS (Multi-Channel Set)

When using MDC [1], SVC [3], 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 buffer.

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 is in 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)

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

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]   Suman Banerjee, Bobby Bhattacharjee, and Christopher Kommareddy. Scalable application layer multicast, volume 32. ACM, 2002.

[3]   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.

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

[5]   Douglas E Comer and Ralph E Droms. Computer networks and internets. Prentice-Hall, Inc., 2003.

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