Iroh는 공개 키(public key)를 이용한 다이얼링(dialing) API를 제공합니다. 사용자가 “저 전화로 연결해 줘”라고 말하면, Iroh는 해당 위치에 관계없이 가장 빠른 연결을 찾아 유지해 줍니다.
가장 빠른 경로는 직접 연결(direct connection)이므로, 필요할 경우 Iroh는 홀 펀칭(hole-punching)을 시도합니다. 이것이 실패하더라도 공개 릴레이 서버(public relay servers)의 개방형 생태계로 폴백(fall back) 할 수 있습니다. 이러한 연결이 가능한 한 빨라지도록 저희는 Iroh를 지속적으로 측정하고 개선하고 있습니다.
Iroh는 noq를 사용하여 엔드포인트 간에 QUIC 연결을 설정합니다. 이를 통해 인증된 암호화(authenticated encryption), 스트림 우선순위가 적용되는 동시 스트림(concurrent streams with stream priorities), 데이터그램 전송(datagram transport)을 얻고, 기본적으로 헤드-오브-라인 블로킹(head-of-line blocking) 문제를 피할 수 있습니다.
직접 작성하기보다 Iroh 기반의 기존 프로토콜 사용:
직접 코드를 작성하는 것보다 Iroh를 활용하여 구축된 기존 프로토콜을 사용하는 것이 더 쉽습니다.
- iroh-blobs: 키바이트(kilobytes)부터 테라바이트(terabytes)까지 확장 가능한 BLAKE3 기반 콘텐츠 주소 지정 블롭 전송(content-addressed blob transfer)
- iroh-gossip: 평균적인 휴대폰이 처리할 수 있는 리소스만을 요구하며 확장 가능한 발행/구독 오버레이 네트워크(publish-subscribe overlay networks) 구축
- iroh-docs: iroh-blobs 블롭의 최종적으로 일관된(eventually-consistent) 키-값 저장소(key-value store)
- iroh-willow: willow 프로토콜의 (개발 중인) 구현체
Iroh를 사용하기 가장 쉬운 방법은 Rust입니다.
cargo add iroh 명령어로 설치한 후, 연결하는 측(connecting side)에서는 다음과 같이 사용할 수 있습니다:
const ALPN: &[u8] = b"iroh-example/echo/0";
let endpoint = Endpoint::bind().await?;
let conn = endpoint.connect(addr, ALPN).await?;
let (mut send, mut recv) = conn.open_bi().await?;
send.write_all(b"Hello, world!").await?;
send.finish()?;
let response = recv.read_to_end(1000).await?;
assert_eq!(&response, b"Hello, world!");
conn.close(0u32.into(), b"bye!");
endpoint.close().await;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
그리고 수신 대기하는 측(accepting side)에서는 다음과 같이 사용할 수 있습니다:
let endpoint = Endpoint::bind().await?;
let router = Router::builder(endpoint)
.accept(ALPN.to_vec(), Arc::new(Echo))
.spawn()
.await?;
#[derive(Debug, Clone)]
struct Echo;
impl ProtocolHandler for Echo {
async fn accept(&self, connection: Connection) -> Result<()> {
let (mut send, mut recv) = connection.accept_bi().await?;
let bytes_sent = tokio::io::copy(&mut recv, &mut send).await?;
send.finish()?;
connection.closed().await;
Ok(())
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
더 많은 주석이 포함된 전체 예제 코드는 echo.rs에서 확인할 수 있습니다.
또는 다음 중 하나를 사용할 수도 있습니다.