Tech News
← Back to articles

Iroh-Blobs

read original related products more articles

Iroh-blobs 0.95 contains a number of significant new features that are worth explaining in detail. There are several new features that are useful for blobs users and also for iroh users in general.

Let's start with a feature that is essential for blobs itself, but can also be useful for many other protocols.

Connection pool

There is a new connection pool in util::connection_pool . This is useful whenever you have a protocol that has to talk to a large number of endpoints while keeping an upper bound of concurrent open connections. In blobs, this is used whenever you use the downloader to orchestrate blobs downloads from multiple providers.

Iroh connections are relatively lightweight, but even so you don't want to keep thousands of them open at the same time. But opening a new connection every time you do a small exchange with a peer is very wasteful. The ConnectionPool gives you an API to deal with these tradeoffs.

Let's first look at basic usage:

let pool = ConnectionPool :: new (ep, iroh_blobs :: ALPN, Options :: default ()); let conn = pool . get_or_connect (remote_id) ? ; /// use the connection as usual. Copy Copied!

get_or_connect will try to get an existing connection from the pool. If there is none, it will create one and store it. The connection will be kept in the pool for a configurable time. Idle connections will be closed as needed. So you can just use this as a drop-in replacement for endpoint.connect and be sure that you won't ever create an unbounded number of connections.

There are some advanced features that can be configued using non-default options.

pub struct Options { pub idle_timeout : Duration , pub connect_timeout : Duration , pub max_connections : usize , pub on_connected : Option < OnConnected >, } Copy Copied!

... continue reading