<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>mastodon &amp;mdash; musicmatzes blog</title>
    <link>https://beyermatthias.de/tag:mastodon</link>
    <description></description>
    <pubDate>Thu, 03 Dec 2026 18:48:49 +0100</pubDate>
    <item>
      <title>Switching from hugo to writefreely</title>
      <link>https://beyermatthias.de/switching-from-hugo-to-writefreely</link>
      <description>&lt;![CDATA[I&#39;ve been a fan of the #ActivityPub stuff (or rather: the #fediverse) for a long time now, running a #mastodon account on @musicmatze@mastodon.technology for some time already, and I also have a #pixelfed account at @musicmatze@pixelfed.social.&#xA;&#xA;So it is just a logical step to switch the #blogging software I use to an ActivityPub supporting solution as well.&#xA;&#xA;Thus, as of today, this blog runs of writefreely.&#xA;&#xA;Blogging software&#xA;&#xA;I&#39;ve used a lot of different blogging software until now. Most of the time, it was static site compilers, because this way I did not have to maintain (mainly update) the software running the blog. Because I host on uberspace, I am free to chose from a range of solutions though. In the very beginning, I was running ghost as far as I can remember.&#xA;&#xA;Lately, I did write less and less on this blog, which is a shame. I hope that with this new solution, I start writing more often even though I have to have a internet connection while writing (possible workarounds like preparing locally with vim or some markdown editor exist, of course).&#xA;&#xA;Importing old posts&#xA;&#xA;All my old posts were already written in markdown, so importing was not that complicated. I had to apply some vim-skills to my markdown files and then import them into #writefreely, but I had to adapt the timestamps. Also, the formatting sucks with the imported articles and maybe even links are broken.&#xA;&#xA;TBH, that&#39;s not that important to me to make the effort of fixing every single (of the more than 200) articles.&#xA;&#xA;hugo]]&gt;</description>
      <content:encoded><![CDATA[<p>I&#39;ve been a fan of the <a href="https://beyermatthias.de/tag:ActivityPub" class="hashtag"><span>#</span><span class="p-category">ActivityPub</span></a> stuff (or rather: the <a href="https://beyermatthias.de/tag:fediverse" class="hashtag"><span>#</span><span class="p-category">fediverse</span></a>) for a long time now, running a <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> account on <a href="https://beyermatthias.de/@/musicmatze@mastodon.technology" class="u-url mention">@<span>musicmatze@mastodon.technology</span></a> for some time already, and I also have a <a href="https://beyermatthias.de/tag:pixelfed" class="hashtag"><span>#</span><span class="p-category">pixelfed</span></a> account at <a href="https://beyermatthias.de/@/musicmatze@pixelfed.social" class="u-url mention">@<span>musicmatze@pixelfed.social</span></a>.</p>

<p>So it is just a logical step to switch the <a href="https://beyermatthias.de/tag:blogging" class="hashtag"><span>#</span><span class="p-category">blogging</span></a> software I use to an ActivityPub supporting solution as well.</p>

<p>Thus, as of today, this blog runs of <a href="https://writefreely.org">writefreely</a>.</p>

<h2 id="blogging-software" id="blogging-software">Blogging software</h2>

<p>I&#39;ve used a lot of different blogging software until now. Most of the time, it was static site compilers, because this way I did not have to maintain (mainly update) the software running the blog. Because I host on <a href="https://uberspace.de">uberspace</a>, I am free to chose from a range of solutions though. In the very beginning, I was running <a href="https://ghost.org/">ghost</a> as far as I can remember.</p>

<p>Lately, I did write less and less on this blog, which is a shame. I hope that with this new solution, I start writing more often even though I have to have a internet connection while writing (possible workarounds like preparing locally with vim or some markdown editor exist, of course).</p>

<h2 id="importing-old-posts" id="importing-old-posts">Importing old posts</h2>

<p>All my old posts were already written in markdown, so importing was not that complicated. I had to apply some vim-skills to my markdown files and then import them into <a href="https://beyermatthias.de/tag:writefreely" class="hashtag"><span>#</span><span class="p-category">writefreely</span></a>, but I had to adapt the timestamps. Also, the formatting sucks with the imported articles and maybe even links are broken.</p>

<p>TBH, that&#39;s not that important to me to make the effort of fixing every single (of the more than 200) articles.</p>

<p><a href="https://beyermatthias.de/tag:hugo" class="hashtag"><span>#</span><span class="p-category">hugo</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/switching-from-hugo-to-writefreely</guid>
      <pubDate>Tue, 30 Mar 2021 17:14:39 +0200</pubDate>
    </item>
    <item>
      <title>Writing a mastodon bot</title>
      <link>https://beyermatthias.de/writing-a-mastodon-bot</link>
      <description>&lt;![CDATA[Today, I wrote a mastodon bot.&#xA;&#xA;  Shut up and show me the code!&#xA;&#xA;Here you go.&#xA;&#xA;The idea&#xA;&#xA;My idea was, to write a bot that fetches the lastest master from a git&#xA;repository and counts some commits and then posts a message to mastodon about&#xA;what it counted.&#xA;&#xA;Because I always complain about people pushing to the master branch of a big&#xA;community git repository directly, I decided that this would be a perfect fit.&#xA;&#xA;(Whether pushing to master directly is okay and when it is not okay to do this&#xA;is another topic and I won&#39;t discuss this here)&#xA;&#xA;The dependencies&#xA;&#xA;Well, because I didn&#39;t want to implement everything myself, I started pulling&#xA;in some dependencies:&#xA;&#xA;log and envlogger for logging&#xA;structopt, toml, serde and config for argument parsing and config reading&#xA;anyhow because I don&#39;t care too much about error handling. It just has to&#xA;  work&#xA;getset for a bit cleaner code (not strictly necessary, tbh)&#xA;handlebars for templating the status message that will be posted&#xA;elefren as mastodon API crate&#xA;git2 for working with the git repository which the bot posts about&#xA;&#xA;The Plan&#xA;&#xA;How the bot should work was rather clear from the outset. First of all, it&#xA;shouldn&#39;t be a always-running-process. I wanted it to be as simple as possible,&#xA;thus, triggering it via a systemd-timer should suffice.&#xA;Next, it should only fetch the latest commits, so it should be able to work on&#xA;a working clone of a repository. This way, we don&#39;t need another clone of a&#xA;potentially huge repository on our disk.&#xA;The path of the repository should of course not be hardcoded, as shouldn&#39;t the&#xA;&#34;upstream&#34; remote name or the &#34;master&#34; branch name (because you might want to track&#xA;a &#34;release-xyz&#34; branch or because &#34;master&#34; was renamed to something else).&#xA;&#xA;Also, it should be configurable how many hours of commits should be checked.&#xA;Maybe the user wants to run this bot once a day, maybe once a week. Both is possible,&#xA;of course.&#xA;But if the user runs it once a day, they want to check only the commits of the&#xA;last 24 hours.&#xA;If they run it once a week, the last 168 hours would be more appropriate.&#xA;&#xA;The message that gets posted should also not be hardcoded, but a template where&#xA;the variables the bot counted are available.&#xA;&#xA;All the above goes into the configuration file the bot ready (and which can be&#xA;set via the --config option on the bots CLI).&#xA;&#xA;The configuration struct&#xA;for the setup described above&#xA;is rather trivial, as is&#xA;the CLI setup.&#xA;&#xA;The setup&#xA;&#xA;The first things the bot has to do is reading the commandline and the&#xA;configuration after initializing the logger, which is a no-brainer, too:&#xA;&#xA;fn main() -  Result() {&#xA;    envlogger::init();&#xA;    log::debug!(&#34;Logger initialized&#34;);&#xA;&#xA;    let opts = Opts::fromargssafe()?;&#xA;    let config: Conf = {&#xA;        let mut config = ::config::Config::default();&#xA;&#xA;        config&#xA;            .merge(::config::File::from(opts.config().topathbuf()))?&#xA;            .merge(::config::Environment::withprefix(&#34;COMBOT&#34;))?;&#xA;        config.tryinto()?&#xA;    };&#xA;    let mastodondata: elefren::Data = toml::de::fromstr(&amp;std::fs::readtostring(config.mastodondata())?)?;&#xA;&#xA;The mastodon data is read from a configuration file that is different from the&#xA;main configuration file, because it may contain sensitive data and if a user&#xA;wants to put their configuration of the bot into a (public?) git repository,&#xA;they might not want to include this data.&#xA;That&#39;s why I opted for another file here, its format is described in the&#xA;configuration example file (next to the setting where the file actually is).&#xA;&#xA;Next, the mastodon client has to be setup and the repository has to be opened:&#xA;&#xA;    let client = elefren::Mastodon::from(mastodondata);&#xA;    let statuslanguage = elefren::Language::from6391(config.statuslanguage())&#xA;        .okorelse(|| anyhow!(&#34;Could not parse status language code: {}&#34;, config.statuslanguage()))?;&#xA;    log::debug!(&#34;config parsed&#34;);&#xA;&#xA;    let repo = git2::Repository::open(config.repositorypath())?;&#xA;    log::debug!(&#34;Repo opened successfully&#34;);&#xA;&#xA;which is rather trivial, too.&#xA;&#xA;The Calculations&#xA;&#xA;Then, we fetch the appropriate remote branch and count the commits:&#xA;&#xA;    let  = fetchmainremote(&amp;repo, &amp;config)?;&#xA;    log::debug!(&#34;Main branch fetched successfully&#34;);&#xA;&#xA;    let (commits, merges, nonmerges) = countcommitsonmainbranch(&amp;repo, &amp;config)?;&#xA;    log::debug!(&#34;Counted commits successfully&#34;);&#xA;&#xA;    log::info!(&#34;Commits    = {}&#34;, commits);&#xA;    log::info!(&#34;Merges     = {}&#34;, merges);&#xA;    log::info!(&#34;Non-Merges = {}&#34;, nonmerges);&#xA;&#xA;The functions called in this snippet will be described later on.&#xA;Just consider them working for now, and let&#39;s move on to the status posting part&#xA;of the bot now.&#xA;&#xA;First of all, we use the variables to compute the status message using the&#xA;template from the configuration file.&#xA;&#xA;    {&#xA;        let statustext = {&#xA;            let mut hb = handlebars::Handlebars::new();&#xA;            hb.registertemplatestring(&#34;status&#34;, config.statustemplate())?;&#xA;            let mut data = std::collections::BTreeMap::new();&#xA;            data.insert(&#34;commits&#34;, commits);&#xA;            data.insert(&#34;merges&#34;, merges);&#xA;            data.insert(&#34;nonmerges&#34;, nonmerges);&#xA;            hb.render(&#34;status&#34;, &amp;data)?&#xA;        };&#xA;&#xA;Handlebars is a perfect fit for that job, as it is rather trivial to use, albeit&#xA;a very powerful templating language is used.&#xA;The user could, for example, even add some conditions to their template, like if&#xA;there are no commits at all, the status message could just say&#xA;&#34;I&#39;m a lonely bot, because nobody commits to master these days...&#34; or something&#xA;like that.&#xA;&#xA;Next, we build the status object we pass to mastodon, and post it.&#xA;&#xA;        let status = elefren::StatusBuilder::new()&#xA;            .status(statustext)&#xA;            .language(statuslanguage)&#xA;            .build()&#xA;            .expect(&#34;Failed to build status&#34;);&#xA;&#xA;        let status = client.newstatus(status)&#xA;            .expect(&#34;Failed to post status&#34;);&#xA;        if let Some(url) = status.url.asref() {&#xA;            log::info!(&#34;Status posted: {}&#34;, url);&#xA;        } else {&#xA;            log::info!(&#34;Status posted, no url&#34;);&#xA;        }&#xA;        log::debug!(&#34;New status = {:?}&#34;, status);&#xA;    }&#xA;&#xA;    Ok(())&#xA;} // main()&#xA;&#xA;Some logging is added as well, of course.&#xA;&#xA;And that&#39;s the whole main function!&#xA;&#xA;Fetching the repository.&#xA;&#xA;But we are not done yet.&#xA;First of all, we need the function that fetches the remote repository.&#xA;&#xA;Because of the infamous git2 library, this part is rather trivial to implement&#xA;as well:&#xA;&#xA;fn fetchmainremote(repo: &amp;git2::Repository, config: &amp;Conf) -  Result() {&#xA;    log::debug!(&#34;Fetch: {} / {}&#34;, config.originremotename(), config.masterbranchname());&#xA;    repo.findremote(config.originremotename())?&#xA;        .fetch(&amp;[config.masterbranchname()], None, None)&#xA;        .maperr(Error::from)&#xA;}&#xA;&#xA;Here we have a function that takes a reference to the repository as well as a&#xA;reference to our Conf object.&#xA;We then, after some logging, find the appropriate remote in our repository and&#xA;simply call fetch for it.&#xA;In case of Err(), we map that to our anyhow::Error type and return it,&#xA;because the callee should handle that.&#xA;&#xA;Counting the commits&#xA;&#xA;Counting the commits is the last part we need to implement.&#xA;&#xA;fn countcommitsonmainbranch(repo: &amp;git2::Repository, config: &amp;Conf) -  Result(usize, usize, usize) {&#xA;&#xA;The function, like the fetchmainremote function, takes a reference to the&#xA;repository as well as a reference to the Conf object of our program.&#xA;It returns, in case of success, a tuple with three elements.&#xA;I did not add strong typing here, because the codebase is rather small (less&#xA;than 160 lines overall), so there&#39;s not need to be very explicit about the&#xA;types here.&#xA;&#xA;Just keep in mind that the first of the three values is the number of all&#xA;commits, the second is the number of merges and the last is the number of&#xA;non-merges.&#xA;&#xA;That also means:&#xA;&#xA;tuple.0 = tuple.1 + tuple.2&#xA;&#xA;Next, let&#39;s have a variable that holds the branch name&#xA;with the remote, like we&#39;re used from git itself&#xA;(this is later required for git2).&#xA;Also, we need to calculate the timestamp that is the lowest timestamp we&#xA;consider.&#xA;Because our configuration file specifies this in hours rather than seconds, we&#xA;simply  60  60 here.&#xA;&#xA;    let branchname = format!(&#34;{}/{}&#34;, config.originremotename(), config.masterbranchname());&#xA;    let minimumtimeepoch = chrono::offset::Local::now().timestamp() - (config.hourstocheck()  60  60);&#xA;&#xA;    log::debug!(&#34;Branch to count     : {}&#34;, branchname);&#xA;    log::debug!(&#34;Earliest commit time: {:?}&#34;, minimumtimeepoch);&#xA;&#xA;Next, we need to instruct git2 to create a Revwalk object for us:&#xA;&#xA;    let revwalkstart = repo&#xA;        .findbranch(&amp;branchname, git2::BranchType::Remote)?&#xA;        .get()&#xA;        .peeltocommit()?&#xA;        .id();&#xA;&#xA;    log::debug!(&#34;Starting at: {}&#34;, revwalkstart);&#xA;&#xA;    let mut rw = repo.revwalk()?;&#xA;    rw.simplifyfirstparent()?;&#xA;    rw.push(revwalkstart)?;&#xA;&#xA;That can be used to iterate over the history of a branch, starting at a certain&#xA;commit.&#xA;But before we can do that, we need to actually find that commit, which is the&#xA;first part of the above snippet.&#xA;Then, we create a Revwalk object, configure it to consider only the first&#xA;parent (because that&#39;s what we care about) and push the rev to start walking&#xA;from it.&#xA;&#xA;The last bit of the function implements the actual counting.&#xA;&#xA;    let mut commits = 0;&#xA;    let mut merges = 0;&#xA;    let mut nonmerges = 0;&#xA;&#xA;    for rev in rw {&#xA;        let rev = rev?;&#xA;        let commit = repo.findcommit(rev)?;&#xA;        log::trace!(&#34;Found commit: {:?}&#34;, commit);&#xA;&#xA;        if commit.time().seconds() &lt; minimumtimeepoch {&#xA;            log::trace!(&#34;Commit too old, stopping iteration&#34;);&#xA;            break;&#xA;        }&#xA;        commits += 1;&#xA;&#xA;        let ismerge = commit.parentids().count()   1;&#xA;        log::trace!(&#34;Merge: {:?}&#34;, ismerge);&#xA;&#xA;        if ismerge {&#xA;            merges += 1;&#xA;        } else {&#xA;            nonmerges += 1;&#xA;        }&#xA;    }&#xA;&#xA;    log::trace!(&#34;Ready iterating&#34;);&#xA;    Ok((commits, merges, nonmerges))&#xA;}&#xA;&#xA;This is done the simple way, without making use of the excelent iterator API.&#xA;First, we create our variables for counting and then, we use the Revwalk&#xA;object and iterate over it.&#xA;For each rev, we unwrap it using the ? operator and then ask the repo to&#xA;give us the corresponding commit.&#xA;We then check whether the time of the commit is before_ our minimum time and if&#xA;it is, we abort the iteration.&#xA;If it is not, we continnue and count the commit.&#xA;We then check whether the commit has more than one parent, because that is what&#xA;makes a commit a merge-commit, and increase the appropriate variable.&#xA;&#xA;Last but not least, we return our findings to the caller.&#xA;&#xA;Conclusion&#xA;&#xA;And this is it! It was a rather nice journey to implement this bot.&#xA;There isn&#39;t too much that can fail here, some calculations might wrap and result&#xA;in false calculations. Possibly a clippy run would find some things that could&#xA;be improved, of course (feel free to submit patches).&#xA;&#xA;If you want to run this bot on your own instance and for your own repositories,&#xA;make sure to check&#xA;the README file&#xA;first.&#xA;Also, feel free to ask questions about this bot and of course, you&#39;re welcome to&#xA;send patches (make sure to --signoff your commits).&#xA;&#xA;And now, enjoy&#xA;the first post&#xA;of&#xA;the bot.&#xA;&#xA;tags: #mastodon #bot #rust&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Today, I wrote a mastodon bot.</p>

<blockquote><p>Shut up and show me the code!</p></blockquote>

<p><a href="https://git.beyermatthi.as/complainingaboutmastercommits-bot">Here you go</a>.</p>

<h1 id="the-idea" id="the-idea">The idea</h1>

<p>My idea was, to write a bot that fetches the lastest <code>master</code> from a git
repository and counts some commits and then posts a message to mastodon about
what it counted.</p>

<p>Because I always complain about people pushing to the <code>master</code> branch of a big
community git repository directly, I decided that this would be a perfect fit.</p>

<p>(Whether pushing to master directly is okay and when it is not okay to do this
is another topic and I won&#39;t discuss this here)</p>

<h1 id="the-dependencies" id="the-dependencies">The dependencies</h1>

<p>Well, because I didn&#39;t want to implement <em>everything</em> myself, I started pulling
in some dependencies:</p>
<ul><li><code>log</code> and <code>env_logger</code> for logging</li>
<li><code>structopt</code>, <code>toml</code>, <code>serde</code> and <code>config</code> for argument parsing and config reading</li>
<li><code>anyhow</code> because I don&#39;t care too much about error handling. It just has to
work</li>
<li><code>getset</code> for a bit cleaner code (not strictly necessary, tbh)</li>
<li><code>handlebars</code> for templating the status message that will be posted</li>
<li><code>elefren</code> as mastodon API crate</li>
<li><code>git2</code> for working with the git repository which the bot posts about</li></ul>

<h1 id="the-plan" id="the-plan">The Plan</h1>

<p>How the bot should work was rather clear from the outset. First of all, it
shouldn&#39;t be a always-running-process. I wanted it to be as simple as possible,
thus, triggering it via a systemd-timer should suffice.
Next, it should only <em>fetch</em> the latest commits, so it should be able to work on
a working clone of a repository. This way, we don&#39;t need another clone of a
potentially huge repository on our disk.
The path of the repository should of course not be hardcoded, as shouldn&#39;t the
“upstream” remote name or the “master” branch name (because you might want to track
a “release-xyz” branch or because “master” was renamed to something else).</p>

<p>Also, it should be configurable how many hours of commits should be checked.
Maybe the user wants to run this bot once a day, maybe once a week. Both is possible,
of course.
But if the user runs it once a day, they want to check only the commits of the
last 24 hours.
If they run it once a week, the last 168 hours would be more appropriate.</p>

<p>The message that gets posted should also not be hardcoded, but a template where
the variables the bot counted are available.</p>

<p>All the above goes into the configuration file the bot ready (and which can be
set via the <code>--config</code> option on the bots CLI).</p>

<p>The configuration struct
<a href="https://git.beyermatthi.as/complainingaboutmastercommits-bot/tree/src/main.rs?id=63a6fa0c43d885b5f367372c06c578548d0b6384#n9">for the setup described above</a>
is rather trivial, as is
<a href="https://git.beyermatthi.as/complainingaboutmastercommits-bot/tree/src/main.rs?id=63a6fa0c43d885b5f367372c06c578548d0b6384#n33">the CLI setup</a>.</p>

<h1 id="the-setup" id="the-setup">The setup</h1>

<p>The first things the bot has to do is reading the commandline and the
configuration after initializing the logger, which is a no-brainer, too:</p>

<pre><code class="language-rust">fn main() -&gt; Result&lt;()&gt; {
    env_logger::init();
    log::debug!(&#34;Logger initialized&#34;);

    let opts = Opts::from_args_safe()?;
    let config: Conf = {
        let mut config = ::config::Config::default();

        config
            .merge(::config::File::from(opts.config().to_path_buf()))?
            .merge(::config::Environment::with_prefix(&#34;COMBOT&#34;))?;
        config.try_into()?
    };
    let mastodon_data: elefren::Data = toml::de::from_str(&amp;std::fs::read_to_string(config.mastodon_data())?)?;
</code></pre>

<p>The mastodon data is read from a configuration file that is different from the
main configuration file, because it may contain sensitive data and if a user
wants to put their configuration of the bot into a (public?) git repository,
they might not want to include this data.
That&#39;s why I opted for another file here, its format is described in the
configuration example file (next to the setting where the file actually is).</p>

<p>Next, the mastodon client has to be setup and the repository has to be opened:</p>

<pre><code class="language-rust">    let client = elefren::Mastodon::from(mastodon_data);
    let status_language = elefren::Language::from_639_1(config.status_language())
        .ok_or_else(|| anyhow!(&#34;Could not parse status language code: {}&#34;, config.status_language()))?;
    log::debug!(&#34;config parsed&#34;);

    let repo = git2::Repository::open(config.repository_path())?;
    log::debug!(&#34;Repo opened successfully&#34;);
</code></pre>

<p>which is rather trivial, too.</p>

<h1 id="the-calculations" id="the-calculations">The Calculations</h1>

<p>Then, we fetch the appropriate remote branch and count the commits:</p>

<pre><code class="language-rust">    let _ = fetch_main_remote(&amp;repo, &amp;config)?;
    log::debug!(&#34;Main branch fetched successfully&#34;);

    let (commits, merges, nonmerges) = count_commits_on_main_branch(&amp;repo, &amp;config)?;
    log::debug!(&#34;Counted commits successfully&#34;);

    log::info!(&#34;Commits    = {}&#34;, commits);
    log::info!(&#34;Merges     = {}&#34;, merges);
    log::info!(&#34;Non-Merges = {}&#34;, nonmerges);
</code></pre>

<p>The functions called in this snippet will be described later on.
Just consider them working for now, and let&#39;s move on to the status posting part
of the bot now.</p>

<p>First of all, we use the variables to compute the status message using the
template from the configuration file.</p>

<pre><code class="language-rust">    {
        let status_text = {
            let mut hb = handlebars::Handlebars::new();
            hb.register_template_string(&#34;status&#34;, config.status_template())?;
            let mut data = std::collections::BTreeMap::new();
            data.insert(&#34;commits&#34;, commits);
            data.insert(&#34;merges&#34;, merges);
            data.insert(&#34;nonmerges&#34;, nonmerges);
            hb.render(&#34;status&#34;, &amp;data)?
        };
</code></pre>

<p>Handlebars is a perfect fit for that job, as it is rather trivial to use, albeit
a very powerful templating language is used.
The user could, for example, even add some conditions to their template, like if
there are no commits at all, the status message could just say
“I&#39;m a lonely bot, because nobody commits to master these days...” or something
like that.</p>

<p>Next, we build the status object we pass to mastodon, and post it.</p>

<pre><code class="language-rust">        let status = elefren::StatusBuilder::new()
            .status(status_text)
            .language(status_language)
            .build()
            .expect(&#34;Failed to build status&#34;);

        let status = client.new_status(status)
            .expect(&#34;Failed to post status&#34;);
        if let Some(url) = status.url.as_ref() {
            log::info!(&#34;Status posted: {}&#34;, url);
        } else {
            log::info!(&#34;Status posted, no url&#34;);
        }
        log::debug!(&#34;New status = {:?}&#34;, status);
    }

    Ok(())
} // main()
</code></pre>

<p>Some logging is added as well, of course.</p>

<p>And that&#39;s the whole main function!</p>

<h1 id="fetching-the-repository" id="fetching-the-repository">Fetching the repository.</h1>

<p>But we are not done yet.
First of all, we need the function that fetches the remote repository.</p>

<p>Because of the infamous <code>git2</code> library, this part is rather trivial to implement
as well:</p>

<pre><code class="language-rust">fn fetch_main_remote(repo: &amp;git2::Repository, config: &amp;Conf) -&gt; Result&lt;()&gt; {
    log::debug!(&#34;Fetch: {} / {}&#34;, config.origin_remote_name(), config.master_branch_name());
    repo.find_remote(config.origin_remote_name())?
        .fetch(&amp;[config.master_branch_name()], None, None)
        .map_err(Error::from)
}
</code></pre>

<p>Here we have a function that takes a reference to the repository as well as a
reference to our <code>Conf</code> object.
We then, after some logging, find the appropriate remote in our repository and
simply call <code>fetch</code> for it.
In case of <code>Err(_)</code>, we map that to our <code>anyhow::Error</code> type and return it,
because the callee should handle that.</p>

<h1 id="counting-the-commits" id="counting-the-commits">Counting the commits</h1>

<p>Counting the commits is the last part we need to implement.</p>

<pre><code class="language-rust">fn count_commits_on_main_branch(repo: &amp;git2::Repository, config: &amp;Conf) -&gt; Result&lt;(usize, usize, usize)&gt; {
</code></pre>

<p>The function, like the <code>fetch_main_remote</code> function, takes a reference to the
repository as well as a reference to the <code>Conf</code> object of our program.
It returns, in case of success, a tuple with three elements.
I did not add strong typing here, because the codebase is rather small (less
than 160 lines overall), so there&#39;s not need to be <em>very</em> explicit about the
types here.</p>

<p>Just keep in mind that the first of the three values is the number of all
commits, the second is the number of merges and the last is the number of
non-merges.</p>

<p>That also means:</p>

<pre><code>tuple.0 = tuple.1 + tuple.2
</code></pre>

<p>Next, let&#39;s have a variable that holds the branch name
with the remote, like we&#39;re used from git itself
(this is later required for <code>git2</code>).
Also, we need to calculate the timestamp that is the lowest timestamp we
consider.
Because our configuration file specifies this in <em>hours</em> rather than seconds, we
simply <code>* 60 * 60</code> here.</p>

<pre><code class="language-rust">    let branchname = format!(&#34;{}/{}&#34;, config.origin_remote_name(), config.master_branch_name());
    let minimum_time_epoch = chrono::offset::Local::now().timestamp() - (config.hours_to_check() * 60 * 60);

    log::debug!(&#34;Branch to count     : {}&#34;, branchname);
    log::debug!(&#34;Earliest commit time: {:?}&#34;, minimum_time_epoch);
</code></pre>

<p>Next, we need to instruct <code>git2</code> to create a <code>Revwalk</code> object for us:</p>

<pre><code class="language-rust">    let revwalk_start = repo
        .find_branch(&amp;branchname, git2::BranchType::Remote)?
        .get()
        .peel_to_commit()?
        .id();

    log::debug!(&#34;Starting at: {}&#34;, revwalk_start);

    let mut rw = repo.revwalk()?;
    rw.simplify_first_parent()?;
    rw.push(revwalk_start)?;
</code></pre>

<p>That can be used to iterate over the history of a branch, starting at a certain
commit.
But before we can do that, we need to actually <em>find</em> that commit, which is the
first part of the above snippet.
Then, we create a <code>Revwalk</code> object, configure it to consider only the first
parent (because that&#39;s what we care about) and push the rev to start walking
from it.</p>

<p>The last bit of the function implements the actual counting.</p>

<pre><code class="language-rust">    let mut commits = 0;
    let mut merges = 0;
    let mut nonmerges = 0;

    for rev in rw {
        let rev = rev?;
        let commit = repo.find_commit(rev)?;
        log::trace!(&#34;Found commit: {:?}&#34;, commit);

        if commit.time().seconds() &lt; minimum_time_epoch {
            log::trace!(&#34;Commit too old, stopping iteration&#34;);
            break;
        }
        commits += 1;

        let is_merge = commit.parent_ids().count() &gt; 1;
        log::trace!(&#34;Merge: {:?}&#34;, is_merge);

        if is_merge {
            merges += 1;
        } else {
            nonmerges += 1;
        }
    }

    log::trace!(&#34;Ready iterating&#34;);
    Ok((commits, merges, nonmerges))
}
</code></pre>

<p>This is done the simple way, without making use of the excelent iterator API.
First, we create our variables for counting and then, we use the <code>Revwalk</code>
object and iterate over it.
For each <code>rev</code>, we unwrap it using the <code>?</code> operator and then ask the repo to
give us the corresponding commit.
We then check whether the time of the commit is <em>before</em> our minimum time and if
it is, we abort the iteration.
If it is not, we continnue and count the commit.
We then check whether the commit has more than one parent, because that is what
makes a commit a merge-commit, and increase the appropriate variable.</p>

<p>Last but not least, we return our findings to the caller.</p>

<h1 id="conclusion" id="conclusion">Conclusion</h1>

<p>And this is it! It was a rather nice journey to implement this bot.
There isn&#39;t too much that can fail here, some calculations might wrap and result
in false calculations. Possibly a <code>clippy</code> run would find some things that could
be improved, of course (feel free to submit patches).</p>

<p>If you want to run this bot on your own instance and for your own repositories,
make sure to check
<a href="https://git.beyermatthi.as/complainingaboutmastercommits-bot/tree/README.md">the README file</a>
first.
Also, feel free to ask questions about this bot and of course, you&#39;re welcome to
send patches (make sure to <code>--signoff</code> your commits).</p>

<p>And now, enjoy
<a href="https://botsin.space/@complainingaboutmastercommits/105572322090509761">the first post</a>
of
<a href="https://botsin.space/@complainingaboutmastercommits">the bot</a>.</p>

<p>tags: <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:bot" class="hashtag"><span>#</span><span class="p-category">bot</span></a> <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/writing-a-mastodon-bot</guid>
      <pubDate>Sun, 17 Jan 2021 16:40:21 +0100</pubDate>
    </item>
    <item>
      <title>34c3</title>
      <link>https://beyermatthias.de/34c3</link>
      <description>&lt;![CDATA[34c3 was awesome. I prepared a blog article as my recap, though I failed to&#xA;provide enough content. That&#39;s why I will simply list my &#34;toots&#34; from mastodon&#xA;here, as a short recap for the whole congress.&#xA;&#xA;(2017-12-26,  4:04 PM) - Arrived at #34c3&#xA;(2017-12-27,  9:55 AM) - Hi #31c3 ! Arrived in Adams, am excited for the intro talk in less than 65 min! smallYes, I got the tag wrong on this one/small&#xA;(2017-12-27, 10:01 AM) - Oh my god I&#39;m so excited about #34c3 ... this is huge, girls and boys! The best congress ever is about to start!&#xA;(2017-12-27, 10:25 AM) - Be awesome to eachother #34c3 ... so far it works beautifully!&#xA;(2017-12-27, 10:31 AM) - #34c3 first mate is empty.&#xA;(2017-12-27, 10:46 AM) - #34c3 - less than 15 minutes. Oh MY GOOOOOOOOOD&#xA;(2017-12-27, 10:49 AM) - Kinda sad that #fefe won&#39;t do the Fnord this year at #34c3 ... but I also think that this year was to shitty to laugh about it, right?&#xA;(2017-12-27, 10:51 AM) - #34c3 oh my good 10 minutes left!&#xA;(2017-12-27, 11:02 AM) - #34c3 GO GO GO GO!&#xA;(2017-12-27, 11:16 AM) - Vom Spieltrieb zur Wissbegierig! #34c3&#xA;(2017-12-27, 12:17 PM) - People asked me things because I am wearing a #nixos T-shirt! Awesome! #34c3&#xA;(2017-12-27, 12:59 PM) - I really hope i will be able to talk to the #secushare people today #34c3&#xA;(2017-12-27,  1:44 PM) - I talked to even more people about #nixos ... and also about #rust ... #34c3 barely started and is already awesome!&#xA;(2017-12-27,  4:28 PM) - Just found a seat in Adams. Awesome! #34c3&#xA;(2017-12-27,  8:16 PM) -  Single girls of #34c3 - where are you?&#xA;(2017-12-28, 10:25 AM) - Day 2 at #34c3 ... Yeah! Today there will be the #mastodon #meetup ... Really looking forward to that!&#xA;(2017-12-28, 12:32 PM) - Just saw ads for a #rust #wayland compositor on an info screen at #34c3 - yeah, awesome!&#xA;(2017-12-28, 12:37 PM) - First mate today. Boom. I&#39;m awake! #34c3&#xA;(2017-12-28, 12:42 PM) - #mastodon ads on screen! Awesome! #34c3&#xA;(2017-12-28, 12:45 PM) - #taskwarrior ads on screen - #34c3&#xA;(2017-12-28,  3:14 PM) - I think I will not publish a blog post about the #34c3 but simply list all my toots and post that as an blog article. Seems to be much easier.&#xA;(2017-12-28,  3:15 PM) - #34c3 does not feel like a hacker event (at least not like the what I&#39;m used to) because there are so many (beautiful) women around here.&#xA;(2017-12-28,  3:36 PM) - The food in the congress center in Leipzig at #34c3 is REALLY expensive IMO. 8.50 for a burger with some fries is too expensive. And it is even less than the Chili in Hamburg was.&#xA;(2017-12-28,  3:43 PM) - Prepare your toots! #mastodon meetup in less than 15 minutes! #34c3&#xA;(2017-12-28,  3:50 PM) - #34c3 Hi #mastodon #meetup !&#xA;(2017-12-28,  3:55 PM) - Whuha... there are much more people than I&#39;ve expected here at the #mastodon #meetup #34c3&#xA;(2017-12-28,  4:03 PM) - Ok. Small #meetup - or not so small. Awesome. Room is packed. #34c3 awesomeness!&#xA;(2017-12-28,  4:09 PM) - 10 minutes in ... and we&#39;re already discussing pineapples. Community ftw! #34c3 #mastodon #meetup&#xA;(2017-12-28,  4:46 PM) - Limiting sharing of #toots does only work if all instances behave! #34c3 #mastodon #meetup&#xA;(2017-12-28,  4:56 PM) - Who-is-who #34c3 #mastodon #meetup doesn&#39;t work for me... because I don&#39;t know the 300 usernames from the top of my head...&#xA;(2017-12-28,  5:17 PM) - From one #meetup to the next: #nixos ! #34c3&#xA;(2017-12-28,  5:57 PM) - Unfortunately the #nixos community has no space for their #meetup at #34c3 ... kinda ad-hoc now!&#xA;(2017-12-28,  7:58 PM) - Now... Where are all the single ladies? #34c3&#xA;(2017-12-28,  9:27 PM) - #34c3 can we have #trance #music please?&#xA;(2017-12-28,  9:38 PM) - Where are my fellow #34c3 #mastodon #meetup people? Get some #toots posted, come on!&#xA;(2017-12-29,  1:44 AM) - Day 2 ends for me now. #34c3&#xA;(2017-12-29, 10:30 AM) - Methodisch Inkorrekt. Approx. 1k people waiting in line. Not nice. #34c3&#xA;(2017-12-29, 10:43 AM) - Damn. Notebook battery ran out of power last night. Cannot check mails and other unimportant things while waiting in line.  One improvement proposal for #34c3 - more power lines outside hackcenter!&#xA;(2017-12-29, 10:44 AM) - Nice. Now the wlan is breaking down. #34c3&#xA;(2017-12-29, 10:57 AM) - LAOOOOLAAA through the hall! We did it #34c3 !&#xA;(2017-12-30,  3:45 AM) - 9h Party. Straight. I&#39;m dead. #34c3&#xA;(2017-12-30,  9:08 PM) - After some awesome days at the #34c3 I am intellectually burned out now. That&#39;s why the #trance #techno #rave yesterday was exactly the right thing to do!&#xA;(2017-12-30, 11:35 PM) - Where can I get the set from yesterday night Chaos Stage #34c3 ??? Would love to trance into the next year with it!&#xA;(2017-12-31, 11:05 PM) - My first little #34c3 congress résumé: I should continue on #imag and invest even more time.  Not that I do not continue it, but progress is slowing down with the last months of my masters thesis... Understandable I guess.&#xA;&#xA;That was my congress. Yes, there are few toots after 28th... because I was&#xA;really tired by then and also had people to talk to all the time, so little&#xA;time for microblogging there. All in all: It was the best congress so far!&#xA;&#xA;tags: #ccc #social&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>34c3 was awesome. I prepared a blog article as my recap, though I failed to
provide enough content. That&#39;s why I will simply list my “toots” from mastodon
here, as a short recap for the whole congress.</p>
<ul><li>(2017-12-26,  4:04 PM) – Arrived at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-27,  9:55 AM) – Hi <a href="https://beyermatthias.de/tag:31c3" class="hashtag"><span>#</span><span class="p-category">31c3</span></a> ! Arrived in Adams, am excited for the intro talk in less than 65 min! <small>Yes, I got the tag wrong on this one</small></li>
<li>(2017-12-27, 10:01 AM) – Oh my god I&#39;m so excited about <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ... this is huge, girls and boys! The best congress ever is about to start!</li>
<li>(2017-12-27, 10:25 AM) – Be awesome to eachother <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ... so far it works beautifully!</li>
<li>(2017-12-27, 10:31 AM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> first mate is empty.</li>
<li>(2017-12-27, 10:46 AM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> – less than 15 minutes. Oh MY GOOOOOOOOOD</li>
<li>(2017-12-27, 10:49 AM) – Kinda sad that <a href="https://beyermatthias.de/tag:fefe" class="hashtag"><span>#</span><span class="p-category">fefe</span></a> won&#39;t do the Fnord this year at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ... but I also think that this year was to shitty to laugh about it, right?</li>
<li>(2017-12-27, 10:51 AM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> oh my good 10 minutes left!</li>
<li>(2017-12-27, 11:02 AM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> GO GO GO GO!</li>
<li>(2017-12-27, 11:16 AM) – Vom Spieltrieb zur Wissbegierig! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-27, 12:17 PM) – People asked me things because I am wearing a <a href="https://beyermatthias.de/tag:nixos" class="hashtag"><span>#</span><span class="p-category">nixos</span></a> T-shirt! Awesome! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-27, 12:59 PM) – I really hope i will be able to talk to the <a href="https://beyermatthias.de/tag:secushare" class="hashtag"><span>#</span><span class="p-category">secushare</span></a> people today <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-27,  1:44 PM) – I talked to even more people about <a href="https://beyermatthias.de/tag:nixos" class="hashtag"><span>#</span><span class="p-category">nixos</span></a> ... and also about <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> ... <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> barely started and is already awesome!</li>
<li>(2017-12-27,  4:28 PM) – Just found a seat in Adams. Awesome! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-27,  8:16 PM) –  Single girls of <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> – where are you?</li>
<li>(2017-12-28, 10:25 AM) – Day 2 at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ... Yeah! Today there will be the <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> ... Really looking forward to that!</li>
<li>(2017-12-28, 12:32 PM) – Just saw ads for a <a href="https://beyermatthias.de/tag:rust" class="hashtag"><span>#</span><span class="p-category">rust</span></a> <a href="https://beyermatthias.de/tag:wayland" class="hashtag"><span>#</span><span class="p-category">wayland</span></a> compositor on an info screen at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> – yeah, awesome!</li>
<li>(2017-12-28, 12:37 PM) – First mate today. Boom. I&#39;m awake! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28, 12:42 PM) – <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> ads on screen! Awesome! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28, 12:45 PM) – <a href="https://beyermatthias.de/tag:taskwarrior" class="hashtag"><span>#</span><span class="p-category">taskwarrior</span></a> ads on screen – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28,  3:14 PM) – I think I will not publish a blog post about the <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> but simply list all my toots and post that as an blog article. Seems to be much easier.</li>
<li>(2017-12-28,  3:15 PM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> does not feel like a hacker event (at least not like the what I&#39;m used to) because there are so many (beautiful) women around here.</li>
<li>(2017-12-28,  3:36 PM) – The food in the congress center in Leipzig at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> is REALLY expensive IMO. 8.50 for a burger with some fries is too expensive. And it is even less than the Chili in Hamburg was.</li>
<li>(2017-12-28,  3:43 PM) – Prepare your toots! <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> meetup in less than 15 minutes! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28,  3:50 PM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> Hi <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> !</li>
<li>(2017-12-28,  3:55 PM) – Whuha... there are much more people than I&#39;ve expected here at the <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28,  4:03 PM) – Ok. Small <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> – or not so small. Awesome. Room is packed. <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> awesomeness!</li>
<li>(2017-12-28,  4:09 PM) – 10 minutes in ... and we&#39;re already discussing pineapples. Community ftw! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a></li>
<li>(2017-12-28,  4:46 PM) – Limiting sharing of <a href="https://beyermatthias.de/tag:toots" class="hashtag"><span>#</span><span class="p-category">toots</span></a> does only work if all instances behave! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a></li>
<li>(2017-12-28,  4:56 PM) – Who-is-who <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> doesn&#39;t work for me... because I don&#39;t know the 300 usernames from the top of my head...</li>
<li>(2017-12-28,  5:17 PM) – From one <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> to the next: <a href="https://beyermatthias.de/tag:nixos" class="hashtag"><span>#</span><span class="p-category">nixos</span></a> ! <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28,  5:57 PM) – Unfortunately the <a href="https://beyermatthias.de/tag:nixos" class="hashtag"><span>#</span><span class="p-category">nixos</span></a> community has no space for their <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> at <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ... kinda ad-hoc now!</li>
<li>(2017-12-28,  7:58 PM) – Now... Where are all the single ladies? <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-28,  9:27 PM) – <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> can we have <a href="https://beyermatthias.de/tag:trance" class="hashtag"><span>#</span><span class="p-category">trance</span></a> <a href="https://beyermatthias.de/tag:music" class="hashtag"><span>#</span><span class="p-category">music</span></a> please?</li>
<li>(2017-12-28,  9:38 PM) – Where are my fellow <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> <a href="https://beyermatthias.de/tag:meetup" class="hashtag"><span>#</span><span class="p-category">meetup</span></a> people? Get some <a href="https://beyermatthias.de/tag:toots" class="hashtag"><span>#</span><span class="p-category">toots</span></a> posted, come on!</li>
<li>(2017-12-29,  1:44 AM) – Day 2 ends for me now. <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-29, 10:30 AM) – Methodisch Inkorrekt. Approx. 1k people waiting in line. Not nice. <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-29, 10:43 AM) – Damn. Notebook battery ran out of power last night. Cannot check mails and other unimportant things while waiting in line.  One improvement proposal for <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> – more power lines outside hackcenter!</li>
<li>(2017-12-29, 10:44 AM) – Nice. Now the wlan is breaking down. <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-29, 10:57 AM) – LAOOOOLAAA through the hall! We did it <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> !</li>
<li>(2017-12-30,  3:45 AM) – 9h Party. Straight. I&#39;m dead. <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a></li>
<li>(2017-12-30,  9:08 PM) – After some awesome days at the <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> I am intellectually burned out now. That&#39;s why the <a href="https://beyermatthias.de/tag:trance" class="hashtag"><span>#</span><span class="p-category">trance</span></a> <a href="https://beyermatthias.de/tag:techno" class="hashtag"><span>#</span><span class="p-category">techno</span></a> <a href="https://beyermatthias.de/tag:rave" class="hashtag"><span>#</span><span class="p-category">rave</span></a> yesterday was exactly the right thing to do!</li>
<li>(2017-12-30, 11:35 PM) – Where can I get the set from yesterday night Chaos Stage <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> ??? Would love to trance into the next year with it!</li>
<li>(2017-12-31, 11:05 PM) – My first little <a href="https://beyermatthias.de/tag:34c3" class="hashtag"><span>#</span><span class="p-category">34c3</span></a> congress résumé: I should continue on <a href="https://beyermatthias.de/tag:imag" class="hashtag"><span>#</span><span class="p-category">imag</span></a> and invest even more time.  Not that I do not continue it, but progress is slowing down with the last months of my masters thesis... Understandable I guess.</li></ul>

<p>That was my congress. Yes, there are few toots after 28th... because I was
really tired by then and also had people to talk to all the time, so little
time for microblogging there. All in all: It was the best congress so far!</p>

<p>tags: <a href="https://beyermatthias.de/tag:ccc" class="hashtag"><span>#</span><span class="p-category">ccc</span></a> <a href="https://beyermatthias.de/tag:social" class="hashtag"><span>#</span><span class="p-category">social</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/34c3</guid>
      <pubDate>Mon, 01 Jan 2018 16:38:38 +0100</pubDate>
    </item>
    <item>
      <title>Blueprint of a distributed social network on IPFS - and its problems</title>
      <link>https://beyermatthias.de/blueprint-of-a-distributed-social-network-on-ipfs-and-its-problems</link>
      <description>&lt;![CDATA[  #matrix , #ipfs , #scuttlebutt and now #mastodon - We&#39;re living in awesome&#xA;  times! centralization &lt; decentralization/federation &lt; distribution!&#xA;  #lovefortech&#xA;&#xA;(me, April 10, 2017, on mastodon)&#xA;&#xA;The idea&#xA;&#xA;With the rise of protocols like the matrix protocol, activitypub and others,&#xA;decentralized social community platforms like matrix, mastodon and others gained&#xA;power and were made real.&#xA;I consider these platforms, especially mastodon and matrix, to be great steps&#xA;into the future and am using both enthusiastically.&#xA;&#xA;But can we do better? Can we do more distribution,? I think so!&#xA;&#xA;So far we have a twitter-like thumbleblog platform (mastodon), a chat platform&#xA;(matrix) and facebook-like platforms (diaspora and friendica) which&#xA;are federated (some form of decentralization). I think we can make a&#xA;completely distributed social network platform reality today.&#xA;&#xA;Let me reiterate on that: I think, we can make a facebook/googleplus/etc clone&#xA;which works without a central component, today. And I would even go one step&#xA;further and state: All we need for this is IPFS (and&#xA;related technology like IPLD and IPNS)!&#xA;&#xA;This platform would feature personal profiles, publishing&#xA;articles/posts/images/videos/voice messages/etc, instant messaging, following&#xA;others, and all the things one would want in such a platform.&#xA;&#xA;How would it work?&#xA;&#xA;What do we need for this? Well, as stated before: not much!&#xA;From what I can think of, we would need IPFS, some sort of public/private key&#xA;functionality (which IPFS already has), a nice frontend-framework and that&#39;s&#xA;basically it.&#xA;&#xA;Let me tell you how I think such a platform would work.&#xA;&#xA;The moment a user starts the application, the application would boot an IPFS&#xA;node.&#xA;The username and all other information about the profile are added to IPFS as&#xA;structured data.&#xA;If the profile changes because the user edits it, it is added to IPFS again,&#xA;using IPLD to link to its previous version.&#xA;&#xA;If a user adds a post to her profile, that post is added to IPFS as well and&#xA;linked from the profile via IPLD.&#xA;All other nodes are informed about the new content via pubsub and are free to&#xA;pin the new content (the new profile version) or only cache it for a while (or&#xA;to not care at all).&#xA;The post itself could add a link to the IPNS hash of the profile under which the&#xA;post is published. This way, a link from the post to the current version of the&#xA;profile would always exist.&#xA;&#xA;Because the profile always links to its previous version as well as to the&#xA;post content, that would imply that the node the user of the profile runs would&#xA;always keep all data the user adds to the network.&#xA;As the data is only kept by links, the user is free to drop published&#xA;content at any point in time.&#xA;&#xA;This means that basically each operation would &#34;generate&#34; a new profile, which&#xA;is of course published as an IPNS name.&#xA;Following others would be a matter of subscribing to their &#34;pub&#34; channel (as&#xA;in &#34;pubsub&#34;) or their IPNS name.&#xA;&#xA;Chat&#xA;&#xA;A chat application using IPFS is already implemented with&#xA;orbit, so that&#39;s a matter of integrating&#xA;one application into another.&#xA;Peer-to-Peer (or rather Profile-to-Profile) messaging is therefore no problem.&#xA;&#xA;Data format&#xA;&#xA;All the data would be saved in a structured format. For example Json (though&#xA;order of serialization is important, because of cryptographic hashes) or Bson&#xA;or any other data serialization format that is widely adopted.&#xA;&#xA;small&#xA;  Sidenote: As long as it is made clear that any client must support all&#xA;  formats, the format itself doesn&#39;t matter that much.&#xA;  For simplicity of this article, I stick to Json (and also because it is most&#xA;  widely known).&#xA;/small&#xA;&#xA;A Profile(-version) would look roughly like this (consider &#39;ipfs hash&#39; to&#xA;mean &#34;some kind of IPLD link&#34; in this context):&#xA;&#xA;{&#xA;  &#34;previous&#34;: [ &#34;ipfs hash&#34; ],&#xA;  &#34;post&#34;: {&#xA;    &#34;type&#34;: &#34;post type&#34;,&#xA;    &#34;nodes&#34;: [&#34;ipfs hash&#34;],&#xA;    &#34;metadata&#34;: {&#xA;      &#34;date&#34;: &#34;2017-12-12T12:00:00+0200&#34;,&#xA;      &#34;tags&#34;: [],&#xA;      &#34;category&#34;: &#34;kittens&#34;,&#xA;      &#34;custom&#34;: {}&#xA;    }&#xA;  }&#xA;}&#xA;&#xA;Let me explain:&#xA;&#xA;The previous key would point to the previous profile version(s).&#xA;  It would only contain IPFS hashes (Why plural, see below in&#xA;  &#34;Multi-Device Support&#34;).&#xA;The post key would contain information about the post published with this&#xA;  profile version.&#xA;  The type of the post could be &#34;article&#34;, &#34;image&#34;, &#34;video&#34;... normal stuff.&#xA;    But also &#34;biography&#34; for the biography shown on the profile or other things.&#xA;    Even &#34;username&#34; would be possible, for adding a user name to the profile.&#xA;  The nodes key would point to an IPFS hash containing the actual payload;&#xA;    either the text of the article (only one hash then) or the ipfs hashes of&#xA;    the pictures, the video(s) or other binary content.&#xA;    Of course, posts could be formatted using Markdown, reStructured Text or&#xA;    whatever format one likes to use. It would be a clients job to render it&#xA;    properly.&#xA;  The metadata field would contain plain meta information, like&#xA;    published date, tags, category and also custom metainformation as&#xA;    key-value pairs.&#xA;&#xA;Maybe a version attribute for protocol version could be added as well.&#xA;Of course, this should be considered an incomplete example, as I almost&#xA;certainly forgot things here.&#xA;&#xA;The idea of linking the previous version of a profile from each new version of&#xA;the profile is very much blockchain-like, of course, with the difference that&#xA;nobody needs to fetch the whole chain but only the latest one to get a&#xA;profile.&#xA;The more content a viewer of the profile wants to see, the more she needs to&#xA;traverse the graph of profile versions (and automatically caching the content&#xA;for others).&#xA;This would automatically result in older content beeing &#34;forgotten&#34; slowly&#xA;(but the content would not be forgotten until the publisher itself and all&#xA;other &#34;pinners&#34; drop it).&#xA;Because the actual payload is not stored in the fetched data, the actual&#xA;amount of data which is required to simply view a profile is rather small.&#xA;A client could be configured to fetch all textual content of a file, but not&#xA;more than 10 versions, or one screenpage, or something like that. The&#xA;possibilities are endless here.&#xA;&#xA;Federated component&#xA;&#xA;One might think &#34;If I go offline with my node, my posts are not accessible if&#xA;nobody else is online having them&#34;. And that&#39;s true.&#xA;&#xA;That&#39;s why I would introduce a federated component, which would run a&#xA;stripped-down version of the application.&#xA;&#xA;As soon as another instance connects and a new post is announced via pubsub,&#xA;the instance automatically pins or caches it.&#xA;Of course, this would mean that all of these federated instances would pin all&#xA;content, which is surely not nice.&#xA;One (rather simple and maybe even stupid) option would be to roll a dice and&#xA;make the chance that a post is pinned a 50-50 thing, or something like that.&#xA;Also, posts which are pinned for a certain amount of time are most likely&#xA;distributed well enough so the federated component nodes can drop them...&#xA;maybe after 90 days, maybe after 10... Details!&#xA;&#xA;Blockchain-Approaches&#xA;&#xA;The fundamental problem with Blockchains is that every peer in the network&#xA;hosts the complete content. Nobody benefits from that, especially if you think&#xA;of a social network which should also work on mobile devices.&#xA;With users loading up images, videos and other large blobs of data, a&#xA;blockchain is the wrong approach.&#xA;&#xA;That&#39;s why I think a social network on Euthereum, Bitcoin or any other&#xA;crypto-currency/blockchain is not an option at all.&#xA;&#xA;IPLD&#xA;&#xA;IPLD can be used not only to link posts and profiles, but&#xA;also to link from content to content. Namely to link from one post to another,&#xA;from a post to an image, a video, a voice message,...&#xA;but also to link from one post to a git commit, an euthereum transaction or&#xA;any other IPLD-supported data structure.&#xA;&#xA;Once nice detail is that one does not have to traverse these links.&#xA;If a user sees a post which links to other posts, for example, she does not&#xA;have to fetch these links to see the post itself, only if she wants to see the&#xA;linked content.&#xA;Caching nodes, on the other hand, can automatically traverse the whole graph&#xA;and fetch all the content into their cache.&#xA;&#xA;That makes a IPLD-based linking approach really beneficial.&#xA;&#xA;Scuttlebutt&#xA;&#xA;Scuttlebutt is a first step into the right direction.&#xA;One can say what one wants about electron and the whole technology stack which&#xA;is used in Scuttlebutt (and like or dislike the whole Javascript world), but&#xA;so far Scuttlebutt seems like the first social network that is completely&#xA;distributed.&#xA;&#xA;I thought about whether it would be a great idea to port Scuttlebutt to use&#xA;IPFS in the backend.&#xA;From what I know right now, it would be a nice way of bringing IPFS and IPLD&#xA;to the mix and therefor enhancing and extending the capabilities of&#xA;Scuttlebutt itself.&#xA;&#xA;I have not final conclusion on that thought, though.&#xA;&#xA;Problems&#xA;&#xA;There are several problems one has to think about when designing such a&#xA;system.&#xA;&#xA;Comments on Posts (and comments)&#xA;&#xA;Consider you want to comment on a post. Of course you create new content,&#xA;which links to the post you just commented.&#xA;But the person who wrote the original post does not automatically link to your&#xA;comment, so is neither able to find the comment (which could be solved via&#xA;pubsub), nor are others able to find them.&#xA;&#xA;The approach to this problem is simple: Notification about comments can be&#xA;done via pubsub.&#xA;And, if a user gets a notification about a new comment, she can approve it and&#xA;automatically publish a new version of her post, with some added meta information:&#xA;&#xA;A link to the comment&#xA;A link to the &#34;old version of the content in IPFS&#34;&#xA;&#xA;Now, if a client fetches all posts of a profile, it resolves all entries for&#xA;their newest version (so basically the one entry which does not link to an&#xA;older version of itself) and only shows the latest versions of it.&#xA;&#xA;Comments on comments (and so on) would be possible with the exact same approach.&#xA;That would, of course, cause a whole tree of comments to be rebuild every time&#xA;a new comment is added.&#xA;&#xA;Maybe not the best idea in that regard.&#xA;&#xA;Multi-Device Support&#xA;&#xA;There are several problems regarding multi-device support.&#xA;&#xA;Publishing content&#xA;&#xA;Publishing from multiple devices with the same profile is possible - one just&#xA;needs to import the private key for the signatures and the profile information&#xA;to the other device.&#xA;&#xA;Though, this needs some sort of merging mechanism if two posts are published&#xA;from two devices (or more) at the same time / without the other devices beeing&#xA;online to get notifications of the new point of truth.&#xA;&#xA;As creating two posts from two seperate devices would create two new versions of&#xA;the profile (because of IPLD linking), which means two points of truth suddenly&#xA;exists, a merging-mechanism must be implemented to merged multiple points of&#xA;truth for the profile.&#xA;This could yield a rather large network of profile versions, but ultimatively&#xA;a DAG (Directed Acyclic Graph).&#xA;&#xA;        Profile Init&#xA;             ^&#xA;             |&#xA;          Post A&#xA;             ^&#xA;             |&#xA;          Post B &lt;----+&#xA;             ^        |&#xA;             |        |&#xA;  +-----  Post C    Post C&#39;&#xA;  |          ^        ^&#xA;  |          |        |&#xA;Post D    Post D&#39;   Post D&#39;&#39;&#xA;  ^          ^        ^&#xA;  |          |        |&#xA;  |          +--------+&#xA;  |          |&#xA;  |       Post E&#xA;  |          ^&#xA;  |          |&#xA;  +----------+&#xA;             |&#xA;             |&#xA;          Post F&#xA;&#xA;A scenario like the one above (each Post also represents a new version of&#xA;the profile) would be easy to create with three devices:&#xA;&#xA;One starts using the network on a notebook&#xA;Post A published from the notebook&#xA;Post B published from the notebook&#xA;Profile added on the workstation&#xA;Post C published from the notebook while off of the internet&#xA;Post C&#39; published on the workstation&#xA;Profile added to the mobile phone (from the notebook)&#xA;Post D published from the mobile while off of the internet&#xA;Post D&#39; published from the notebook while off of the internet&#xA;Post D&#39;&#39; published on the workstation&#xA;Notebook comes back online, Post E published, merging the state from&#xA;   Post D&#39;&#39; from the workstation and Post D&#39; from the notebook itself.&#xA;Phone comes online, one of the devices is used to publish Post F, merging&#xA;   the state from Post D and Post E.&#xA;&#xA;In this scenario, there would still be one problem, though: If the profile is&#xA;published as an IPNS name, branching off of versions would be problematic.&#xA;If C is published while C&#39; is published, both devices would publish their&#xA;version as an IPNS name.&#xA;Now, first come first serve applies. And of course that is problematic,&#xA;because every device would always see one of the posts, but no device could see&#xA;the other.&#xA;Only at E (in the above example), when the branches are merged, both C and&#xA;C&#39; would be visible (though D wouldn&#39;t be visible as long as it isn&#39;t&#xA;merged into the chain).&#xA;But how does a device discover that there are two &#34;current&#34; versions which&#xA;have to be linked to the new post?&#xA;&#xA;So, discoverability is an issue in this approach. Maybe someone can come up&#xA;with a clean and easy solution that would work for netsplit and all those&#xA;scenarios.&#xA;&#xA;One idea would be that there is a profile-key which is used to publish profile&#xA;versions under an IPNS name as well as a device-key, which is used to&#xA;announce profile versions as a seperate IPNS name.&#xA;That IPNS name could be added to the profile, so each other device can find it&#xA;and fetch &#34;current&#34; versions from each device.&#xA;Only the initial setup of a new device would need to be made carefully then.&#xA;&#xA;Or, maybe, the whole approach is wrong and another approach would fit better&#xA;for this kind of problem. I don&#39;t know.&#xA;&#xA;Subscribing&#xA;&#xA;Another issue with multi-device support would be subscribing. For example, if&#xA;a user (lets call her Amy) subscribes to another user (lets call him Sheldon) on&#xA;her Notebook, this information needs to be stored somehow.&#xA;And because Amys machines do not necessarily sync with each other, her&#xA;mobile phone may never know that following Sheldon is a thing now!&#xA;&#xA;This problem could by solved by storing the &#34;follow&#34;-information in her public&#xA;profile. Although, some users might not like everyone to know who to follow.&#xA;Cryptographic things could be considered to fix visibility.&#xA;&#xA;But then, users may want to &#34;categorize&#34; their friends, store them in groups&#xA;or whatever. This information would be stored in the public profile as well,&#xA;which would create even more noise on the network.&#xA;Also, because cryptography is hard and information would be stored forever,&#xA;this might not be an option as some day, the crypto might be broken and reveal&#xA;all the things that were stored privately before.&#xA;&#xA;Deleting profile versions&#xA;&#xA;Some time, a user may want to remove a biography entry or a user name she once&#xA;published.&#xA;Because all the information is chained in a long chain of versions, one may&#xA;think that deleting a node is not possible.&#xA;But it is!&#xA;&#xA;Consider the following (simple) graph of profile versions:&#xA;&#xA;A&lt;---B&lt;---C&lt;---D&lt;---E&#xA;&#xA;If the user now wants to delete node C in this graph, she simply drops it.&#xA;Now, E beeing the latest point of truth, one may think that finding B and&#xA;A is not possible anymore. That&#39;s true. But why not shipping around this by&#xA;creating a new profile version and linking the previous versions:&#xA;&#xA;A&lt;---B     &lt;---D&lt;---E&lt;---F&#xA;      \                 /&#xA;       -----------------&#xA;&#xA;Of course, D would now point to a node which does not exist. But that is not&#xA;a problem. Indeed, its a fundamental concept of the idea - that content may be&#xA;unavailable.&#xA;&#xA;F must not contain new content. It even should not, because dropping F&#xA;because of its content becomes harder this way. Also, new versions of the&#xA;profile is simple and cheap.&#xA;&#xA;Problems are hard in distributed environments&#xA;&#xA;I do not claim to know the final solution to any of these problems. Its just&#xA;that I think of them and would love to get an open conversation started on the&#xA;whole subject of distributed social networks and problems that come with them.&#xA;&#xA;tags:  #distributed #network #open-source #social #software&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<blockquote><p><a href="https://beyermatthias.de/tag:matrix" class="hashtag"><span>#</span><span class="p-category">matrix</span></a> , <a href="https://beyermatthias.de/tag:ipfs" class="hashtag"><span>#</span><span class="p-category">ipfs</span></a> , <a href="https://beyermatthias.de/tag:scuttlebutt" class="hashtag"><span>#</span><span class="p-category">scuttlebutt</span></a> and now <a href="https://beyermatthias.de/tag:mastodon" class="hashtag"><span>#</span><span class="p-category">mastodon</span></a> – We&#39;re living in awesome
times! centralization &lt; decentralization/federation &lt; distribution!
<a href="https://beyermatthias.de/tag:lovefortech" class="hashtag"><span>#</span><span class="p-category">lovefortech</span></a></p></blockquote>

<p>(me, April 10, 2017, on <a href="https://mastodon.fun/@musicmatze/11236">mastodon</a>)</p>

<h1 id="the-idea" id="the-idea">The idea</h1>

<p>With the rise of protocols like the matrix protocol, activitypub and others,
decentralized social community platforms like matrix, mastodon and others gained
power and were made real.
I consider these platforms, especially mastodon and matrix, to be great steps
into the future and am using both enthusiastically.</p>

<p>But can we do better? Can we do <em>more</em> distribution,? I think so!</p>

<p>So far we have a twitter-like thumbleblog platform (mastodon), a chat platform
(matrix) and facebook-like platforms (diaspora and friendica) which
are federated (some form of decentralization). I think we can make a
<em>completely distributed social network platform</em> reality <em>today</em>.</p>

<p>Let me reiterate on that: I think, we can make a facebook/googleplus/etc clone
which works without a central component, today. And I would even go one step
further and state: All we need for this is <a href="https://ipfs.io">IPFS</a> (and
related technology like <a href="https://ipld.io/">IPLD</a> and IPNS)!</p>

<p>This platform would feature personal profiles, publishing
articles/posts/images/videos/voice messages/etc, instant messaging, following
others, and all the things one would want in such a platform.</p>

<h1 id="how-would-it-work" id="how-would-it-work">How would it work?</h1>

<p>What do we need for this? Well, as stated before: not much!
From what I can think of, we would need IPFS, some sort of public/private key
functionality (which IPFS already has), a nice frontend-framework and that&#39;s
basically it.</p>

<p>Let me tell you how I think such a platform would work.</p>

<p>The moment a user starts the application, the application would boot an IPFS
node.
The username and all other information about the profile are added to IPFS as
structured data.
If the profile changes because the user edits it, it is added to IPFS again,
using IPLD to link to its previous version.</p>

<p>If a user adds a post to her profile, that post is added to IPFS as well and
linked from the profile via IPLD.
All other nodes are informed about the new content via pubsub and are free to
pin the new content (the new profile version) or only cache it for a while (or
to not care at all).
The post itself could add a link to the IPNS hash of the profile under which the
post is published. This way, a link from the post to the current version of the
profile would always exist.</p>

<p>Because the profile always links to its previous version as well as to the
post content, that would imply that the node the user of the profile runs would
always keep all data the user adds to the network.
As the data is only kept by <em>links</em>, the user is free to drop published
content at any point in time.</p>

<p>This means that basically each operation would “generate” a new profile, which
is of course published as an IPNS name.
Following others would be a matter of subscribing to their “pub” channel (as
in “pubsub”) or their IPNS name.</p>

<h1 id="chat" id="chat">Chat</h1>

<p>A chat application using IPFS is already implemented with
<a href="https://github.com/orbitdb/orbit">orbit</a>, so that&#39;s a matter of integrating
one application into another.
Peer-to-Peer (or rather Profile-to-Profile) messaging is therefore no problem.</p>

<h1 id="data-format" id="data-format">Data format</h1>

<p>All the data would be saved in a structured format. For example Json (though
order of serialization is important, because of cryptographic hashes) or Bson
or any other data serialization format that is widely adopted.</p>

<p><small>
  Sidenote: As long as it is made clear that any client must support <em>all</em>
  formats, the format itself doesn&#39;t matter that much.
  For simplicity of this article, I stick to Json (and also because it is most
  widely known).
</small></p>

<p>A Profile(-version) would look roughly like this (consider <code>&#39;ipfs hash&#39;</code> to
mean “some kind of IPLD link” in this context):</p>

<pre><code class="language-json">{
  &#34;previous&#34;: [ &#34;&lt;ipfs hash&gt;&#34; ],
  &#34;post&#34;: {
    &#34;type&#34;: &#34;&lt;post type&gt;&#34;,
    &#34;nodes&#34;: [&#34;&lt;ipfs hash&gt;&#34;],
    &#34;metadata&#34;: {
      &#34;date&#34;: &#34;2017-12-12T12:00:00+0200&#34;,
      &#34;tags&#34;: [],
      &#34;category&#34;: &#34;kittens&#34;,
      &#34;custom&#34;: {}
    }
  }
}
</code></pre>

<p>Let me explain:</p>
<ul><li>The <code>previous</code> key would point to the previous profile version(s).
It would only contain IPFS hashes (Why <em>plural</em>, see below in
“Multi-Device Support”).</li>
<li>The <code>post</code> key would contain information about the post published with this
profile version.
<ul><li>The <code>type</code> of the post could be “article”, “image”, “video”... normal stuff.
But also “biography” for the biography shown on the profile or other things.
Even “username” would be possible, for adding a user name to the profile.</li>
<li>The <code>nodes</code> key would point to an IPFS hash containing the actual payload;
either the text of the article (only one hash then) or the ipfs hashes of
the pictures, the video(s) or other binary content.
Of course, posts could be formatted using Markdown, reStructured Text or
whatever format one likes to use. It would be a clients job to render it
properly.</li>
<li>The <code>metadata</code> field would contain plain meta information, like
published date, tags, category and also custom metainformation as
key-value pairs.</li></ul></li></ul>

<p>Maybe a <code>version</code> attribute for protocol version could be added as well.
Of course, this should be considered an incomplete example, as I almost
certainly forgot things here.</p>

<p>The idea of linking the previous version of a profile from each new version of
the profile is very much blockchain-like, of course, with the difference that
nobody needs to fetch the <em>whole</em> chain but only the latest one to get a
profile.
The more content a viewer of the profile wants to see, the more she needs to
traverse the graph of profile versions (and automatically caching the content
for others).
This would automatically result in older content beeing “forgotten” slowly
(but the content would not be forgotten until the publisher itself and all
other “pinners” drop it).
Because the actual <em>payload</em> is not stored in the fetched data, the actual
amount of data which is required to simply <em>view</em> a profile is rather small.
A client could be configured to fetch all textual content of a file, but not
more than 10 versions, or one screenpage, or something like that. The
possibilities are endless here.</p>

<h1 id="federated-component" id="federated-component">Federated component</h1>

<p>One might think “If I go offline with my node, my posts are not accessible if
nobody else is online having them”. And that&#39;s true.</p>

<p>That&#39;s why I would introduce a federated component, which would run a
stripped-down version of the application.</p>

<p>As soon as another instance connects and a new post is announced via pubsub,
the instance automatically pins or caches it.
Of course, this would mean that all of these federated instances would pin all
content, which is surely not nice.
One (rather simple and maybe even stupid) option would be to roll a dice and
make the chance that a post is pinned a 50-50 thing, or something like that.
Also, posts which are pinned for a certain amount of time are most likely
distributed well enough so the federated component nodes can drop them...
maybe after 90 days, maybe after 10... Details!</p>

<h1 id="blockchain-approaches" id="blockchain-approaches">Blockchain-Approaches</h1>

<p>The fundamental problem with Blockchains is that every peer in the network
hosts the complete content. Nobody benefits from that, especially if you think
of a social network which should also work on mobile devices.
With users loading up images, videos and other large blobs of data, a
blockchain is the wrong approach.</p>

<p>That&#39;s why I think a social network on Euthereum, Bitcoin or any other
crypto-currency/blockchain is not an option at all.</p>

<h1 id="ipld" id="ipld">IPLD</h1>

<p><a href="https://ipld.io/">IPLD</a> can be used not only to link posts and profiles, but
also to link from content to content. Namely to link from one post to another,
from a post to an image, a video, a voice message,...
but also to link from one post to a git commit, an euthereum transaction or
any other IPLD-supported data structure.</p>

<p>Once nice detail is that one does not have to traverse these links.
If a user sees a post which links to other posts, for example, she does not
have to fetch these links to see the post itself, only if she wants to see the
linked content.
Caching nodes, on the other hand, can automatically traverse the whole graph
and fetch all the content into their cache.</p>

<p>That makes a IPLD-based linking approach really beneficial.</p>

<h1 id="scuttlebutt" id="scuttlebutt">Scuttlebutt</h1>

<p>Scuttlebutt is a first step into the right direction.
One can say what one wants about electron and the whole technology stack which
is used in Scuttlebutt (and like or dislike the whole Javascript world), but
so far Scuttlebutt seems like the first social network that is completely
distributed.</p>

<p>I thought about whether it would be a great idea to port Scuttlebutt to use
IPFS in the backend.
From what I know right now, it would be a nice way of bringing IPFS and IPLD
to the mix and therefor enhancing and extending the capabilities of
Scuttlebutt itself.</p>

<p>I have not final conclusion on that thought, though.</p>

<h1 id="problems" id="problems">Problems</h1>

<p>There are several problems one has to think about when designing such a
system.</p>

<h2 id="comments-on-posts-and-comments" id="comments-on-posts-and-comments">Comments on Posts (and comments)</h2>

<p>Consider you want to comment on a post. Of course you create new content,
which links to the post you just commented.
But the person who wrote the original post does not automatically link to your
comment, so is neither able to find the comment (which could be solved via
pubsub), nor are others able to find them.</p>

<p>The approach to this problem is simple: Notification about comments can be
done via pubsub.
And, if a user gets a notification about a new comment, she can approve it and
automatically publish a new version of her post, with some added meta information:</p>
<ul><li>A link to the comment</li>
<li>A link to the “old version of the content in IPFS”</li></ul>

<p>Now, if a client fetches all posts of a profile, it resolves all entries for
their newest version (so basically the one entry which does not link to an
older version of itself) and only shows the latest versions of it.</p>

<p>Comments on comments (and so on) would be possible with the exact same approach.
That would, of course, cause a whole tree of comments to be rebuild every time
a new comment is added.</p>

<p>Maybe not the best idea in that regard.</p>

<h2 id="multi-device-support" id="multi-device-support">Multi-Device Support</h2>

<p>There are several problems regarding multi-device support.</p>

<h3 id="publishing-content" id="publishing-content">Publishing content</h3>

<p>Publishing from multiple devices with the same profile is possible – one just
needs to import the private key for the signatures and the profile information
to the other device.</p>

<p>Though, this needs some sort of merging mechanism if two posts are published
from two devices (or more) at the same time / without the other devices beeing
online to get notifications of the new point of truth.</p>

<p>As creating two posts from two seperate devices would create two new versions of
the profile (because of IPLD linking), which means two points of truth suddenly
exists, a merging-mechanism must be implemented to merged multiple points of
truth for the profile.
This could yield a rather large network of profile versions, but ultimatively
a DAG (Directed Acyclic Graph).</p>

<pre><code>        Profile Init
             ^
             |
          Post A
             ^
             |
          Post B &lt;----+
             ^        |
             |        |
  +-----&gt; Post C    Post C&#39;
  |          ^        ^
  |          |        |
Post D    Post D&#39;   Post D&#39;&#39;
  ^          ^        ^
  |          |        |
  |          +--------+
  |          |
  |       Post E
  |          ^
  |          |
  +----------+
             |
             |
          Post F

</code></pre>

<p>A scenario like the one above (each <code>Post</code> also represents a new version of
the profile) would be easy to create with three devices:</p>
<ol><li>One starts using the network on a notebook</li>
<li>Post <code>A</code> published from the notebook</li>
<li>Post <code>B</code> published from the notebook</li>
<li>Profile added on the workstation</li>
<li>Post <code>C</code> published from the notebook while off of the internet</li>
<li>Post <code>C&#39;</code> published on the workstation</li>
<li>Profile added to the mobile phone (from the notebook)</li>
<li>Post <code>D</code> published from the mobile while off of the internet</li>
<li>Post <code>D&#39;</code> published from the notebook while off of the internet</li>
<li>Post <code>D&#39;&#39;</code> published on the workstation</li>
<li>Notebook comes back online, Post <code>E</code> published, merging the state from
<code>Post D&#39;&#39;</code> from the workstation and <code>Post D&#39;</code> from the notebook itself.</li>
<li>Phone comes online, one of the devices is used to publish <code>Post F</code>, merging
the state from <code>Post D</code> and <code>Post E</code>.</li></ol>

<p>In this scenario, there would still be one problem, though: If the profile is
published as an IPNS name, branching off of versions would be problematic.
If <code>C</code> is published while <code>C&#39;</code> is published, both devices would publish their
version as an IPNS name.
Now, first come first serve applies. And of course that is problematic,
because every device would always see one of the posts, but no device could see
the other.
Only at <code>E</code> (in the above example), when the branches are merged, both <code>C</code> and
<code>C&#39;</code> would be visible (though <code>D</code> wouldn&#39;t be visible as long as it isn&#39;t
merged into the chain).
But how does a device discover that there are two “current” versions which
have to be linked to the new post?</p>

<p>So, discoverability is an issue in this approach. Maybe someone can come up
with a clean and easy solution that would work for netsplit and all those
scenarios.</p>

<p>One idea would be that there is a profile-key which is used to publish profile
versions under an IPNS name as well as a <em>device</em>-key, which is used to
announce profile versions as a seperate IPNS name.
That IPNS name could be added to the profile, so each other device can find it
and fetch “current” versions from each device.
Only the initial setup of a new device would need to be made carefully then.</p>

<p>Or, maybe, the whole approach is wrong and another approach would fit better
for this kind of problem. I don&#39;t know.</p>

<h3 id="subscribing" id="subscribing">Subscribing</h3>

<p>Another issue with multi-device support would be subscribing. For example, if
a user (lets call her Amy) subscribes to another user (lets call him Sheldon) on
her Notebook, this information needs to be stored somehow.
And because Amys machines do not necessarily sync with each other, her
mobile phone may never know that following Sheldon is a thing now!</p>

<p>This problem could by solved by storing the “follow”-information in her public
profile. Although, some users might not like everyone to know who to follow.
Cryptographic things could be considered to fix visibility.</p>

<p>But then, users may want to “categorize” their friends, store them in groups
or whatever. This information would be stored in the public profile as well,
which would create even <em>more</em> noise on the network.
Also, because cryptography is hard and information would be stored forever,
this might not be an option as some day, the crypto might be broken and reveal
all the things that were stored privately before.</p>

<h2 id="deleting-profile-versions" id="deleting-profile-versions">Deleting profile versions</h2>

<p>Some time, a user may want to remove a biography entry or a user name she once
published.
Because all the information is chained in a long chain of versions, one may
think that deleting a node is not possible.
But it is!</p>

<p>Consider the following (simple) graph of profile versions:</p>

<pre><code>A&lt;---B&lt;---C&lt;---D&lt;---E
</code></pre>

<p>If the user now wants to delete node <code>C</code> in this graph, she simply drops it.
Now, <code>E</code> beeing the latest point of truth, one may think that finding <code>B</code> and
<code>A</code> is not possible anymore. That&#39;s true. But why not shipping around this by
creating a new profile version and linking the previous versions:</p>

<pre><code>A&lt;---B     &lt;---D&lt;---E&lt;---F
      \                 /
       -----------------
</code></pre>

<p>Of course, <code>D</code> would now point to a node which does not exist. But that is not
a problem. Indeed, its a fundamental concept of the idea – that content may be
unavailable.</p>

<p><code>F</code> must not contain new content. It even <em>should</em> not, because dropping <code>F</code>
because of its content becomes harder this way. Also, new versions of the
profile is simple and cheap.</p>

<h2 id="problems-are-hard-in-distributed-environments" id="problems-are-hard-in-distributed-environments">Problems are hard in distributed environments</h2>

<p>I do not claim to know the final solution to any of these problems. Its just
that I think of them and would love to get an open conversation started on the
whole subject of distributed social networks and problems that come with them.</p>

<p>tags:  <a href="https://beyermatthias.de/tag:distributed" class="hashtag"><span>#</span><span class="p-category">distributed</span></a> <a href="https://beyermatthias.de/tag:network" class="hashtag"><span>#</span><span class="p-category">network</span></a> <a href="https://beyermatthias.de/tag:open" class="hashtag"><span>#</span><span class="p-category">open</span></a>-source <a href="https://beyermatthias.de/tag:social" class="hashtag"><span>#</span><span class="p-category">social</span></a> <a href="https://beyermatthias.de/tag:software" class="hashtag"><span>#</span><span class="p-category">software</span></a></p>
]]></content:encoded>
      <guid>https://beyermatthias.de/blueprint-of-a-distributed-social-network-on-ipfs-and-its-problems</guid>
      <pubDate>Tue, 31 Oct 2017 16:38:24 +0100</pubDate>
    </item>
  </channel>
</rss>