What is Bitswap?

Bitswap protocol version 1.2.0 has recently landed in js-IPFS and brings a host of performance improvements around coordinating the supply of blocks across the network to peers. Machine learning experts suggest that BitSwap will expand shortly, in terms of its applications and presence. With Bitswap, peers can respond to WANTs with messages saying they have the block but not sending it, to send multiple blocks in one message later rather than many small messages, resulting in fewer chat network operations and faster overall transfer times. 

 

Learning of Blog

  • Overview
  • How Bitswap works?
  • Bitswap improvements for p2p image distribution
  • Netflix Collaboration for Better Bitswap
  • Conclusion

 

In this article, we discuss more about BitSwap and how it is getting better each day.

 

Overview

Bitswap is an IPFS core module for exchanging data blocks. It directs the request and dispatch of blocks to and from other network peers. Bitswap is a protocol based on messages where want-lists or blocks are included in all messages. Bitswap has an implementation of Go and an implementation of JavaScript. 

There are two primary jobs on Bitswap: 

  1. To acquire blocks requested from the network by the client. 
  2. To send blocks to other peers that want them in their possession.

 

How Bitswap works?

IPFS breaks up files into blocks called chunks of data. These blocks are recognized by a content identifier (CID). They send out want-lists to other peers when nodes running the Bitswap protocol want to fetch a file. A want-list is a list of CIDs a peer wants to receive for blocks. Each node identifies which blocks its peers want. It examines if any of its peers want the block each time a node receives a block and transfers it to them if they do. The Bitswap version we are now using is still a bit of a work-in-process, but it already works great. BitSwap looks pretty straightforward, but there’s a lot of complexity baked in because a BitSwapping peer must have strategies to decide when and to whom to send blocks of data, as in a BitTorrent swarm. Otherwise, we would get leeches on the network and unfair exchange practices.

 

 

  • Discovery 

 

A node operating the Bitswap protocol first sends a request called a want-have to all the peers to which it is connected to find peers that have a file. This request contains the CID of the file’s root block (the root block is located at the top of the DAG of the blocks that make up the file). A response is sent by peers with the root block and added to a session. Peers who don’t have the block send a response that they don’t have. Bitswap queries the Distributed Hash Table (DHT) to request who can provide the root block if none of the peers have the root block.

 

 

  • Transfer

 

Once peers have been joined to a session, Bitswap sends want-have to each session peer for each block the client wants, to find out which peers have the block. With have or don’t have, peers, respond. Bitswap creates a map of which nodes each block has and doesn’t have. To peers who have the block, Bitswap sends want-block, and they respond with the block itself. Bitswap requests the DHT to find providers who have the block if no peers have the block.

 

Bitswap improvements for p2p image distribution

The IPFS team made some modifications to the way Bitswap fetches blocks to improve the performance and efficiency of Bitswap.

 

  • A node initially wants to know which of its peers has the root block but does not want to receive the block itself (because many peers want to receive this “discovery”). So one new change is that it can ask for a HAVE message in response when Bitswap sends a want (instead of getting the entire block back). 
  • Once a node has supplemented peers to the session, these HAVE messages can also be used to determine which of the session peers have the rest of the blocks it needs comparatively cheaply because duplicate blocks do not have to worry about. The node also requires the peer to say whether it does not have the block at this stage. So we added a response to DONT HAVE.
  • A node can reasonably work out how blocks are distributed among its peers with these changes, and can more accurately direct the requests for blocks, increasing the overall download speed and reducing duplicate blocks. When all peers in a session don’t own a block it needs, the node can also quickly recognize and go out to the DHT to find out who has the block.

 

Netflix Collaboration for Better Bitswap

Netflix and IPFS began collaborating on integrating peer-to-peer services into Netflix’s developer tools after IPFS Camp 2019. On Titus, the Netflix container management platform, Netflix creators routinely deploy millions of containers. Since many of these containers handle critical Netflix-powered workloads, they often need to be deployed in many regions worldwide, scaling the traffic in that geographic location accordingly. The image must be replicated to Docker Registries in other regions, or deployments will suffer from cross-region data costs and slow transfer speeds when developers push a release image to production. The docker registry is intended to decouple the notion of what an image reference such as “alpine” presents and what information is contained through content-addressability inside the image. This is parallel to the data model of IPFS, where its CID always represents data. Because the container runtime can be modified to retrieve layers identified by their CIDs, this is precisely how IPFS can be leveraged as a CDN for container image layers.

 

Conclusion

Bit-Swap, based on deep learning, is a scalable and efficient lossless data compression technique. Bit-Swap has a lot of growth potential in the coming future. Do you have an inclination towards machine learning? There are a lot of machine learning courses available online. Grab your own Machine Learning Certification today!