GitHub - LemmyNet/activitypub-federation-rust: High-level Rust library for the Activitypub protocol
The library has a nice guideand two working examples, so I tried the local_federation
example. To build the example, you need Rust compiler, cargo package manager, and git:
<span style="color:#323232;">$ git clone https://github.com/LemmyNet/activitypub-federation-rust
</span><span style="color:#323232;">$ cd activitypub-federation-rust
</span><span style="color:#323232;">$ cargo run --example local_federation axum
</span><span style="color:#323232;">[INFO local_federation] Start with parameter `axum` or `actix-web` to select the webserver
</span><span style="color:#323232;">[INFO local_federation::axum::http] Listening with axum on localhost:8001
</span><span style="color:#323232;">[INFO local_federation::axum::http] Listening with axum on localhost:8002
</span><span style="color:#323232;">[INFO local_federation] Local instances started
</span><span style="color:#323232;">[INFO local_federation] Alpha user follows beta user via webfinger
</span><span style="color:#323232;">[INFO activitypub_federation::fetch] Fetching remote object http://localhost:8002/.well-known/webfinger?resource=acct:beta@localhost:8002
</span><span style="color:#323232;">[INFO activitypub_federation::fetch] Fetching remote object http://localhost:8002/beta
</span><span style="color:#323232;">[INFO activitypub_federation::fetch] Fetching remote object http://localhost:8001/alpha
</span><span style="color:#323232;">[INFO local_federation] Follow was successful
</span><span style="color:#323232;">[INFO local_federation] Beta sends a post to its followers
</span><span style="color:#323232;">[INFO local_federation] Alpha received post: Hello world!
</span><span style="color:#323232;">[INFO local_federation] Test completed
</span>
You may want to use network analizyer (e.g, wireshark) to see how it works under the hood.
<span style="color:#323232;">GET /.well-known/webfinger?resource=acct:beta@localhost:8002 HTTP/1.1
</span><span style="color:#323232;">accept: application/jrd+json
</span><span style="color:#323232;">digest: SHA-256=[redacted]
</span><span style="color:#323232;">signature: keyId="http://localhost:8001/#main-key",algorithm="hs2019",[...]
</span><span style="color:#323232;">host: localhost:8002
</span><span style="color:#323232;">
</span><span style="color:#323232;">HTTP/1.1 200 OK
</span><span style="color:#323232;">content-type: application/json
</span><span style="color:#323232;">content-length: 269
</span><span style="color:#323232;">date: Sat, 03 Feb 2024 23:05:19 GMT
</span><span style="color:#323232;">
</span><span style="color:#323232;">{
</span><span style="color:#323232;"> "subject": "acct:beta@localhost:8002",
</span><span style="color:#323232;"> "links": [
</span><span style="color:#323232;"> {
</span><span style="color:#323232;"> "rel": "http://webfinger.net/rel/profile-page",
</span><span style="color:#323232;"> "type": "text/html",
</span><span style="color:#323232;"> "href": "http://localhost:8002/beta",
</span><span style="color:#323232;"> "template": null
</span><span style="color:#323232;"> },
</span><span style="color:#323232;"> {
</span><span style="color:#323232;"> "rel": "self",
</span><span style="color:#323232;"> "type": "application/activity+json",
</span><span style="color:#323232;"> "href": "http://localhost:8002/beta",
</span><span style="color:#323232;"> "template": null
</span><span style="color:#323232;"> }
</span><span style="color:#323232;"> ]
</span><span style="color:#323232;">}
</span><span style="color:#323232;">
</span><span style="color:#323232;">[...]
</span>
Add comment