Ben Kunkle

Anthill Representations of Peer-to-peer Networks


You can run the simulation yourself in the browser!

Introduction to Peer to Peer Networks

Many of the websites and services we use on a day to day basis are housed and run on centralized servers. While centralized servers have their beneifits, by virtue of being centralized they come with comprimises. A centralized server means governments or individuals looking to intercept certain traffic or shut down a service have a single target.

An anternative is the Peer-to-peer (P2P) network. In a P2P network users talk directly to each other rather than through a centralized server.

A visual comparison between a centralized and a peer-to-peer Network source

A full comparison between the two is beyond the scope of this piece. For more in depth comparisons of Peer-to-peer and centralized networks as well as examples of how Peer-to-peer networks are used check out these articles:

A Problem With Peer-to-peer Networks

Figuring out where to get the data you want, such as a video, file, or website within a P2P network can be difficult as there isn't necessarily a centralized system keeping track of what urls lead where. There are many ways of searching for the desired data including many “deterministic” approaches such as the well known BitTorrent protocol. However S. Apel and E. Buchmann claim these approaches “leave aside that: peers want to obtain queries at different rates, some keys are more popular than others, and peers can be less reliable” (section 4).

To solve this problem S. Apel and E. Buchmann as well as others took inspiration from ants. Ants have to deal with similar problems when searching for food. The food could be anywhere and some food sources are better than others. To solve this problem ants leave pheromones in their path. Future ants can then simply follow the smelliest path to go where the most of their fellow ants have gone. This allows them to quickly organize and accomplish complicated tasks collaboratively without requiring a queen to control them all.

To explore this idea I decided to create a program that simulated an Anthill inspired P2P network

Implementing an Anthill Inspired P2P Network

The ants pheromone system can be implemented in a P2P network in various albeit similar ways, however I decided to use the approach taken by A. Montresor and O. Babaoglu in the aptly named Anthill framework for the overall design, with some implementation details taken from the excellent Sebastian Lague Video on simulating ants and slime molds.

In this framework each "peer" or participant in the network is thought of as an Anthill with various ants representing the tasks the anthill is capable of such as retrieving a website. When these ants are called upon to carry out actions, they leave information related to their current task at each anthill they visit. This data left behind is the pheromones that can guide future ants trying to accomplish the same task. Ideally, through this system efficient pathways to popular sites, files, etc are formed so they are easier and take less time to find.

The simulation I created goes through the following steps

  1. Create a "map" with circles of various colors to represent each nest

  2. The empty map

  3. For each nest randomly decide whether to make a request.
    This represents getting a website, downloading a file, sending a chat message etc.

  4. If the nest is making a request:

The ants logic while wandering is as follows:

  1. for all the nests the ant could travel to: evaluate how good of a next place to go it is.
    this is calculated as $$f_d \cdot f_r \cdot f_p$$ where: The powers \(p_d\), \(p_r\), \(p_p\) are each manaully configured to control the impact each factor has

  2. the "goodness" of each nest is then divided by the sum of the goodness' for each nest to get a percentage

  3. a nest is then chosen at random using a weighted average where each weight is it's calculated goodness

  4. the ant then travels to the chosen nest increasing the pheromone strength of the ants parent nest
    . The parent nests pheromone strength is increased as a sort of trail of bread crumbs leading back home

  5. once the ant reaches it's ultimate target it picks up an orb of the target nests color and wanders home

You can run the simulation yourself in the browser!

Or you can watch a (now outdated) time lapse of the simulation below.