% !BIB TS-program = biber
%!TeX program=pdflatex
%!TeX encoding=utf8
%!TeX spellcheck = en_US



\gdef\doctype{extbook}
\documentclass[a4paper,appendixprefix,pdfusetitle,twocolumn,fontsize=12pt,DIV=calc,12pt,final,utf8]{\doctype} %scrbook
% add attachdocs to attach all documents
% add openany to avoid empty pages

% add encoding spec
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% fix some fonts
\usepackage{sansmath}                  % Maths without serifes
\usepackage{microtype}                 % better text distribution in lines

% Workarround for book
\makeatletter
\newcommand\subtitle[1]{\gdef\@subtitle{#1}}
\makeatother

\PassOptionsToPackage{table,svgnames}{xcolor}

% enable breakable URLS
\PassOptionsToPackage{hyphens}{url}

\usepackage{colortbl}

% Make C&P work
\usepackage{cmap}

% Some index related settings
%\usepackage{imakeidx}
%\makeindex[columns=3, title=Alphabetical Index]
\usepackage{makeidx}
\makeindex

\makeatletter
\let\inserttitle\@title
\makeatother

%\makeatletter
%\def\title#1{\gdef\@title{#1}\gdef\thetitle{#1}}
%\makeatother

\PassOptionsToPackage{final}{graphicx}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,arrows.meta,backgrounds,shapes.geometric,shadows.blur}
\tikzset{background rectangle/.style={fill=black!10}, show background rectangle}

\usepackage[draft=false,automark]{scrlayer-scrpage}
% and make some nice page headers
\automark{part}
\automark*{chapter}
\clearpairofpagestyles
\ihead{\headmark}
\ohead{\pagemark}

\setheadsepline{0.55pt}
\setkomafont{headsepline}{\color{black}}
\definecolor{head}{rgb}{0.01, 0.28, 1.0}

\gdef\thetitle{MessageVortex}
\title{\thetitle}
\gdef\thesubtitle{Transport Independent, Unobservable, and Unlinkable Messaging}
\subtitle{\thesubtitle}
\author{Martin Gwerder (06-073-787)}
%\date{\gitAuthorDate}
\gdef\myabstract{
	In this thesis, we introduce an unobservable message anonymization protocol named MessageVortex. It is based on the zero-trust principle, has a distributed peer-to-peer (P2P) architecture, and avoids central aspects such as fixed infrastructures within a global network. It scores over existing work by blending its traffic into suitable standard transport protocols like SMTP, making it next to impossible to block it without significantly affecting regular users of the transport medium. No additional protocol-specific infrastructure is required in public networks and allows a sender to control all aspects of a message, such as the degree of anonymity, timing, and redundancy of the message transport, without disclosing any of these details to routing or transporting nodes. We have made our prototype implementation publicly available and added an RFC-style document that contains all necessary information to build a MessageVortex node, see https://messagevortex.net/.
}
\makeatother

% for PDF/A generation
\makeatletter
\@ifclasswith{\doctype}{attachdocs}{
	\usepackage[
	  pdfencoding=unicode,
	  psdextra,
	  bookmarks,
	  hyperindex,
	  hyperfigures,
	  pdfpagelabels,
	  final]{hyperref}
}{
	\typeout{INFO: ======================}
	\typeout{INFO: creating PDF/A}
	\typeout{INFO: ======================}
	\PassOptionsToPackage{
  	  pdfencoding=unicode,
	  psdextra,
	  bookmarks,
	  hyperindex,
	  hyperfigures,
	  pdfpagelabels,
	  final}{hyperref}
	%\usepackage[a-1b]{pdfx}
	\catcode30=12
}
\makeatother

%enable hyperlinks
\RequirePackage{hyperref}
\makeatletter
\hypersetup{	
	pdfpagelayout=TwoPageRight,
	linktoc=all,
	breaklinks=true,
	hidelinks,
	pdfstartview=Fit,
	pdfauthor={\author},
	pdftitle={\thetitle - \thesubtitle},
	pdflang=en,
	pdfsubject={\myabstract},
	pdfkeywords={Messaging, Anonymity, SMTP, Message Vortex},
%	pdfcontactemail={martin.gwerder@fhnw.ch},
%	pdflicenseurl={http://creativecommons.org/licenses/by-nc-nd/3.0/ch/},
%	pdfcopyright={Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 Switzerland (CC BY-NC-ND 3.0 CH)}
%	pdfcaptionwriter   = {Martin Gwerder},
%	pdfcontactaddress  = {Bahnhofstrasse 5},
%	pdfcontactcity     = {CH-5212 Windisch},
%	pdfcontactcountry  = {Switzerland},
%	pdfmetalang        = {en}
}
\makeatother



% XMP support 
%\usepackage{hyperxmp}
%\usepackage{xmpincl}
%\makeatletter
%\includexmp{pdfa-1b}
%\makeatother

% enable superscript  for 1st, 2nd, 3rd etc.
\usepackage[super]{nth}

% extended width for toc page numbers
\usepackage[titles]{tocloft}
\cftsetpnumwidth{3em}
% Format appendix
\setlength{\cftchapnumwidth}{16pt}%
%\renewcommand{\cftpartpresnum}{\partname\hspace{13pt}}
\renewcommand{\cftchappresnum}{\chaptername\hspace{5pt}}
\renewcommand{\cftchapaftersnum}{\hspace{5pt}}

% Extract filename from path
\makeatletter
\DeclareRobustCommand{\filenameExtract}[1]{%
 \begingroup
  % \lstname seems to change hyphens into \textendash
  \def\textendash{-}%
  \filename@parse{#1}%
  \edef\filename@base{\detokenize\expandafter{\filename@base}}%
  \texttt{\filename@base.\filename@ext}%
 \endgroup
}
\makeatother

% PDF/a measures
% embed color profile 
%\immediate\pdfobj stream attr{/N 3} file{sRGB_IEC61966-2-1_black_scaled.ICC}
%\pdfcatalog{%
%	/OutputIntents [ <<
%	/Type /OutputIntent
%	/S/GTS_PDFA1
%	/DestOutputProfile \the\pdflastobj\space 0 R
%	/OutputConditionIdentifier (sRGB IEC61966-2-1 black scaled)
%	/Info(sRGB IEC61966-2-1 black scaled)
%	>> ]
%}
% map glyphs 
\input{glyphtounicode.tex}
\input{glyphtounicode-cmr.tex}
\pdfgentounicode=1
% deactivate LZW compression
\pdfobjcompresslevel=0
\pdfinclusioncopyfonts=1

% Table environments
\usepackage{booktabs}
\newcommand*\rot{\rotatebox{90}}

\usepackage{xstring}

\usepackage{pdfsync} 

%\usepackage{MnSymbol} % required for the arrow

%\usepackage{underscore}

% No new page for chapters
\usepackage{etoolbox}
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother

% hidden sections and subsections
\newcommand{\hiddensubsubsection}[1]{
	\stepcounter{subsubsection}
	\subsection*{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}\hspace{1em}{#1}}
}
\newcommand{\hiddensubsection}[1]{
	\stepcounter{subsection}
	\subsection*{\arabic{chapter}.\arabic{section}.\arabic{subsection}\hspace{1em}{#1}}
}
\newcommand{\hiddensection}[1]{
	\stepcounter{section}
	\subsection*{\arabic{chapter}.\arabic{section}\hspace{1em}{#1}}
}

% titlepage geometry change
\usepackage[paper=a4paper,top=2cm,bottom=2cm,inner=3.1cm,outer=2.2cm]{geometry}% http://ctan.org/pkg/geometry

% Pagestyles
% For formulae in twocolumn
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{cuted}

% line breaking in math mode
%\usepackage{scrhack}

\usepackage[autocite=superscript,
            backref=true,
            backend=biber,
            hyperref=true,
            url=true,
            isbn=true,
            maxcitenames=3,
            minbibnames=1,
            maxbibnames=300,
            bibencoding=utf8,
            block=none,
            sorting=anyt]{biblatex}

%\bibstyle{alphadin}
\addbibresource{messageVortex.bib}
%\addbibresource{inc/bib/unclassified/Anonbib/anonbib}
\usepackage{csquotes}

% For Multipage listing in appendix
\usepackage[final]{listings}
\usepackage{caption}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}
\usepackage{multicol}% for multiple column listings
\usepackage{float} % for defining floats
\newfloat{lstfloat}{htbp}{lop}
\floatname{lstfloat}{Listing}
\def\lstfloatautorefname{Listing} % needed for hyperref/auroref
\lstset{commentstyle=\color{darkgray}}
\lstdefinelanguage[]{asn.1}{
	keywords={DEFINITIONS,SEQUENCE,OCTET,INTEGER,BEGIN,END,OPTIONAL,STRING},
	sensitive=true,
	comment=[l]{--}, % l is for line comment
	string=[b]", % defines that strings are enclosed in double quotes
} 


% enable raggedright in tables
\usepackage{array}
% for diagonal divided cells in tables
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

% footnotes for tables
\usepackage{tablefootnote}
%\makesavenoteenv{tabular}
%\makesavenoteenv{table}

% enable placement of floating images
\usepackage{float}

%enable page spanning tables
\usepackage{supertabular}

% Link above tables and figures
%\usepackage[hypcap]{caption}

% support repetitive footnotes
\usepackage{fixfoot}

% Support for algorithms
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algnewcommand{\AbstractFunction}[2]{\State \textbf{abstract function} \textproc{#1}(#2) \{\ldots\};}%
\algdef{SE}% flags used internally to indicate we're defining a new block statement
[OBJECT]% new block type, not to be confused with loops or if-statements
{Object}% "\Struct{name}" will indicate the start of the struct declaration
{EndObject}% "\EndStruct" ends the block indent
[1]% There is one argument, which is the name of the data structure
{\textbf{object} \textsc{#1}}% typesetting of the start of a struct
{\textbf{end object}}% typesetting the end of the struct
%set font size of algorithms
\makeatletter
\renewcommand{\ALG@beginalgorithmic}{\scriptsize}
\makeatother
% boolean operators
\algnewcommand\And{~\textbf{and}~}
\algnewcommand\Or{~\textbf{or}~}
\algnewcommand\Not{~\neg~}
\algnewcommand\Throw{\State \textbf{throw}~}
\algnewcommand{\LineComment}[1]{\State {\ttfamily\textcolor{blue}{\(\triangleright\) #1}}}


\usepackage{caption}
\newcounter{nalg}[chapter] % defines algorithm counter for chapter-level
\renewcommand{\thenalg}{\thechapter .\arabic{nalg}} %defines appearance of the algorithm counter
\DeclareCaptionLabelFormat{algocaption}{Algorithm \thenalg} % defines a new caption label as Algorithm x.y
% Allow pagebreak in algorithms
\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
	\begin{center}
		\refstepcounter{algorithm}% New algorithm
		\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
		\renewcommand{\caption}[2][\relax]{% Make a new \caption
			{\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
			\ifx\relax##1\relax % #1 is \relax
			\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
			\else % #1 is not \relax
			\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
			\fi
			\kern2pt\hrule\kern2pt
		}
	}{% \end{breakablealgorithm}
		\kern2pt\hrule\relax% \@fs@post for \@fs@ruled
	\end{center}
}
\makeatother
%linebreak in algorithms 
\algrenewcommand{\algorithmicreturn}{\State \textbf{return}}
\newcommand\CONDITION[2]%
{\begin{tabular}[t]{@{}l@{}l@{}}
		#1&#2
	\end{tabular}%
}
\algdef{SE}[WHILE]{While}{EndWhile}[1]%
{\algorithmicwhile\ \CONDITION{#1}{\ \algorithmicdo}}%
{\algorithmicend\ \algorithmicwhile}
\algdef{SE}[FOR]{For}{EndFor}[1]%
{\algorithmicfor\ \CONDITION{#1}{\ \algorithmicdo}}%
{\algorithmicend\ \algorithmicfor}
\algdef{S}[FOR]{ForAll}[1]%
{\algorithmicforall\ \CONDITION{#1}{\ \algorithmicdo}}
\algdef{SE}[REPEAT]{Repeat}{Until}{\algorithmicrepeat}[1]%
{\algorithmicuntil\ \CONDITION{#1}{}}
\algdef{SE}[IF]{If}{EndIf}[1]%
{\algorithmicif\ \CONDITION{#1}{\ \algorithmicthen}}%
{\algorithmicend\ \algorithmicif}%
\algdef{C}[IF]{IF}{ElsIf}[1]%
{\algorithmicelse\ \algorithmicif\ \CONDITION{#1}{\ \algorithmicthen}}
%references to functions
\makeatletter
\renewcommand{\Function}[2]{%
	\csname ALG@cmd@\ALG@L @Function\endcsname{#1}{#2}%
	\def\jayden@currentfunction{#1}%
}
\newcommand{\funclabel}[1]{%
	\@bsphack
	\protected@write\@auxout{}{%
		\string\newlabel{#1}{{\jayden@currentfunction}{\thepage}{}{}{}}%
	}%
	\@esphack
}
\renewcommand{\Procedure}[2]{%
	\csname ALG@cmd@\ALG@L @Procedure\endcsname{#1}{#2}%
	\def\jayden@currentprocedure{#1}%
}
\newcommand{\proclabel}[1]{%
	\@bsphack
	\protected@write\@auxout{}{%
		\string\newlabel{#1}{{\jayden@currentprocedure}{\thepage}{}{}{}}%
	}%
	\@esphack
}
\newcommand{\funcref}[1]{\@bsphack\textproc{\ref{#1}}\@esphack}
\makeatother
% Euler number
\newcommand{\euler}{\mathrm{e}}


%\lstnewenvironment{algorithm}[1][] %defines the algorithm listing environment
%{   
%	\refstepcounter{nalg} %increments algorithm number
%	\captionsetup{labelformat=algocaption,labelsep=colon} %defines the caption setup for: it ises label format as the declared caption label above and makes label and caption text to be separated by a ':'
%	\lstset{ %this is the stype
%		mathescape=true,
%		frame=tB,
%		numbers=left, 
%		numberstyle=\tiny,
%		basicstyle=\scriptsize, 
%		keywordstyle=\color{black}\bfseries\em,
%		keywords={,input, output, return, datatype, function, in, if, else, foreach, while, begin, end, } %add the keywords you want, or load a language as Rubens explains in his comment above.
%		numbers=left,
%		xleftmargin=.04\textwidth,
%		#1 % this is to add specific settings to an usage of this environment (for instnce, the caption and referable label)
%	}
%}
%{}
% Document annotations
\usepackage[nomargin]{fixme}
\fxsetup{layout=pdfnote}

%enable attached files
\usepackage[color=black]{attachfile}
\usepackage{embedfile}
\usepackage{hypgotoe}

% graphs
\usepackage{pgfplots}

%enable word separation
\usepackage[english]{babel}

% enable nice references
\usepackage{fancyref}

% format appendix
\usepackage{bookmark}
\usepackage[]{appendix} %enable appendix 

\let\oldappendices\appendices
\renewcommand{\appendices}{%
	\oldappendices
	\bookmarksetupnext{level=-1}
	\addtocontents{toc}{\protect\renewcommand\protect\cftpartpresnum{}}
	\addcontentsline{toc}{part}{Appendices}
	\addtocontents{toc}{\protect\renewcommand\protect\cftchappresnum{}%
		\protect\setlength\protect\cftchapnumwidth{15pt}}%
}

% citations
%\usepackage{cite}

%fonts for comparison table 
\usepackage{pifont,wasysym,fontawesome,txfonts,marvosym,fontawesome}

% colored tables 
\usepackage{colortbl}


% Sans serif font for the whole document
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage{times}

\usepackage{amsmath}

% No paragraph indentation
\setlength\parindent{0pt} 
\setlength\parskip{6pt} 

% For coments and similar
\usepackage{verbatim}

% For Page background color
\usepackage{afterpage}
\usepackage[table]{xcolor} 


\usepackage{tabularx}
\usepackage{multirow}

% Required for definitions environment
\usepackage{hanging}
\usepackage{ragged2e}
\newenvironment{entry}{\par\leavevmode\hangpara{1.5mm}{1}\ignorespaces}{\RaggedRight\par}
\newcommand*{\mainentry}[2]{{\bfseries{#1\label{def:#1}}}~#2\par}
\newcommand*{\subentry}[2]{\par~\begin{minipage}{\columnwidth-0.6cm}{\bfseries{\itshape{#1\label{def:#1}}}}~#2\end{minipage}}

\newcommand*{\defref}[1]{\hyperref[def:#1]{#1}}
\title{\thetitle}
\subtitle{\thesubtitle}
\author{Martin Gwerder}
\date{\gitAuthorDate}

%\hypersetup{pdfinfo={
%Subject={Privacy when using common Internet transport protocols},
%
%}}

\lstset{ %
	backgroundcolor=\color{lightgray},   
	language=java,
	frame=single,
	numbers=left,
	numbersep=5pt,
	numberstyle=\tiny,
	basicstyle=\tiny,
	frame=tb,
	xleftmargin=.05\columnwidth, 
	xrightmargin=.05\columnwidth,
}

\lstdefinelanguage{EBNF}%
{
	morestring=[b]',%
	morestring=[b]",%
	morecomment=[s]{?}{?},%
	morecomment=[s]{(*}{*)},%
}

\lstdefinelanguage{ASN1}
{
	morekeywords=[1]{DEFINITIONS,AUTOMATIC,TAGS,BEGIN,END,%
		SEQUENCE,OF,CHOICE,ENUMERATED,NULL,SIZE,OPTIONAL,%
		OCTET,BIT,STRING,INTEGER,REAL,BOOLEAN,WITH,COMPONENTS},%
	commentstyle=\itshape,%
	morecomment=[l]{--},%
	basicstyle=\tiny\sffamily,
	breaklines=true,
	prebreak={\mbox{\quad$\hookleftarrow$}},
}

\lstdefinelanguage{bash}{
	language={},
	basicstyle=\tiny\ttfamily,
	numbers=none,
	frame=tb,
	%keepspaces=true,
	breaklines=true,
	prebreak={\mbox{\quad$\hookleftarrow$}},
	columns=fullflexible,
	backgroundcolor=\color{gray!20},
    literate=~{$\sim$}2
			{\$}{\$}1
%	linewidth=0.9\linewidth,
%	xleftmargin=0.1\linewidth
}

\hyphenation{an-on-ym-iz-ing an-on-ym-ity al-though weak-ness-es mes-sa-ges know-led-ge}

\makeatletter
\newcommand{\getfilename}[1]{%
	\begingroup
	% \lstname seems to change hyphens into \textendash
	\def\textendash{-}%
	\filename@parse{#1}%
	\texttt{\filename@base.\filename@ext}%
	\endgroup
}
\makeatother

\usepackage{wrapfig}

%% This package will make dealing with the ``requirements'' environment a lot easier:
\usepackage{environ}
\newcounter{requirements}\setcounter{requirements}{0}
\makeatletter
%% This is a macro that gets called by the .aux file to load in data.
\gdef\savedreq#1#2{\expandafter\gdef\csname req#1\endcsname{#2}}
%% This macro will save the given requirement to the .aux file so we will have it during the next LaTeX pass to put in the list:
\def\recordrequirement#1{\immediate\write\@mainaux{\string\savedreq{\the\value{requirements}}{#1}}}

\AtEndDocument{\refstepcounter{requirements}\immediate\write\@mainaux{\string\xdef\string\totalreqsplusone{\the\value{requirements}}}}

\NewEnviron{requirement}[2]{
	\noindent
	\begingroup
	%% Increment the requirement counter
	\refstepcounter{requirements}
	%% Here is the ``Req.'' text:
	%\textbf{RQ\arabic{requirements} (#2)}:
	%% Make a label that we can use to refer to this counter:
	\label{req:\arabic{requirements}}
	\protected@write \@auxout {}{\string \newlabel {req:#1}{{RQ\arabic{requirements} (#2)}{\thepage}{RQ\arabic{requirements} (#2)}{req:#1}{}} }\recordrequirement{\BODY}
	
	%% Next, save this requirement to the .aux file so we will have it during the next LaTeX pass to put in the list:
	%% We will make the remainder italic:
	\textbf{RQ\arabic{requirements} (#2):} \itshape
	\BODY\hypertarget{req:#1}{}
	\endgroup
}
\newcommand{\listofrequirements}{
	\chapter*{List of Requirements}
	%% First, we need to make sure that this is not the first LaTeX pass (i.e., that all of the information has already been recorded to the .aux file):
	\expandafter\ifx\csname totalreqsplusone\endcsname\relax
	Please run \LaTeX\ again to populate this list!
	\else
	\begingroup
	%% This \reqi counter is what we are going to use to iterate over the requirements:
	\newcount\reqi
	\reqi=0
	\loop
	\advance\reqi by 1
	\ifnum\reqi<\totalreqsplusone
	%% The requirement numbered \reqi exists!
	\noindent\textbf{RQ\the\reqi} \csname req\the\reqi\endcsname\leaders\hbox to 2em{\dotfill}\hfill\pageref{req:\the\reqi}\\
	\repeat
	\endgroup
	\fi
}

\newcommand{\slistofrequirements}{
	%% First, we need to make sure that this is not the first LaTeX pass (i.e., that all of the information has already been recorded to the .aux file):
	\expandafter\ifx\csname totalreqsplusone\endcsname\relax
	Please run \LaTeX\ again to populate this list!
	\else
	\begingroup
	%% This \reqi counter is what we are going to use to iterate over the requirements:
	\par
	\newcount\reqi
	\reqi=0
%	\leftskip=25pt
	\loop
	\advance\reqi by 1
	\ifnum\reqi<\totalreqsplusone
	%% The requirement numbered \reqi exists!
	\hangindent=30pt \parbox{30pt}{\textbf{RQ\the\reqi} }\csname req\the\reqi\endcsname\par
	\repeat
	\endgroup
	\fi
}
\makeatother

\captionsetup[lstlisting]{position=bottom}
\captionsetup[lstinputlisting]{position=bottom}


\usepackage[final]{pdfpages}

% How do I make an attached non-pdf file display like a link?
% (http://tex.stackexchange.com/q/230581)
\makeatletter
\newcommand*{\embeddedfilelink}[2]{%
	\begingroup
	\leavevmode
	\pdfstartlink
	attr{%
		\Hy@setpdfborder
		\ifx\@pdfhighlight\@empty
		\else
		/H\@pdfhighlight
		\fi
		\ifx\@filebordercolor\relax
		\else
		/C[\@filebordercolor]%
		\fi
	}%
	user{%
		/Subtype/Link%
		/A<<%
		/Type/Action%
		/S/JavaScript%
		/JS(this.exportDataObject({cName: "#1", nLaunch: 2}))%
		>>%
	}%
	\relax
	\Hy@colorlink\@filebordercolor#2%
	\close@pdflink
	\endgroup
}
\makeatother

\makeatother
\renewcommand*{\bibfont}{\small}

\usepackage{ifdraft}
\newif\ifdraft
%\drafttrue 
%\draftfalse

\makeatletter\@ifclasswith{\doctype}{draft}{\drafttrue\gdef\indexes{\listoffixmes}}{\draftfalse\gdef\indexes{\listoftables\listoffigures\listofrequirements}}\makeatother

\RequirePackage[explicit]{titlesec}

\usepackage[export]{adjustbox}

% Adapt bibtex to include documents  
\makeatletter
\@ifclasswith{\doctype}{attachdocs}{
	\typeout{INFO: ======================}
	\typeout{INFO: attaching files to PDF}
	\typeout{INFO: ======================}
	\DeclareFieldFormat{file}{\StrGobbleLeft{#1}{1}[\wtcGwM]\StrGobbleRight{\wtcGwM}{4}[\filename]
	\IfFileExists{\filename}{\textattachfile[subject={\printfield{ids}_\filenameExtract{\StrGobbleLeft{#1}{1}[\wtcGwM]\StrGobbleRight{\wtcGwM}{4}[\filename]}}]{\filename}{}}{ FIXME missing document link}}
	\renewcommand*{\finentrypunct}{\printfield{file}}%\addperiod
}{}
\makeatother

%%% Specialized Part
\usepackage{titlesec,titletoc}
\usepackage{tikz}
\usepackage{epigraph}
\usepackage{xpatch}

\titleclass{\part}{top}

\let\Oldpart\part
\newcommand{\parttitle}{}
\newcommand\partepigraph[2]{\gdef\partepigraphtext{#1}\gdef\partepigraphauthor{#2}}
\gdef\oldtoc{none}
\renewcommand{\part}[1]{
	\stopcontents
	\Oldpart{#1}
	\renewcommand{\parttitle}{#1}
	\startcontents
	%\vbox{\Large Part Table of Contents}\vskip1ex
	%\rule{\textwidth}{0.4pt}
	%\printcontents{1}{1}{\setcounter{tocdepth}{5}}
    %font\rule{\textwidth}{0.4pt}
	\vskip1ex
	\cleardoublepage
}

\newlength\PartWd
\settowidth\PartWd{\huge\parttitle}

\titleformat{\part}[display]
{\normalfont\filcenter\sffamily}
{\tikz[remember picture,overlay]
	{
		\node[fill=head,font=\fontsize{60}{72}\selectfont\color{white},anchor=north east,minimum size=\PartWd] 
		at ([xshift=-25pt,yshift=-25pt]current page.north east) 
		(numb) {\thepart~};
		\node[rotate=90,anchor=south,inner sep=0pt,font=\huge] at (numb.west) {Part};
	}
}{0pt}{\fontsize{33}{40}\selectfont\color{head}#1}[\vskip10pt\Large***\vskip10pt\epigraph{\partepigraphtext}{\partepigraphauthor}\vskip10pt ]
\titlespacing*{\part}
{5pt}{50pt}{10pt}


\makeatletter
\xpatchcmd{\ttl@printlist}{\endgroup}{{\noindent\color{head}\rule{\textwidth}{1.5pt}}\vskip30pt\endgroup}{}{}
\makeatother

\setlength\epigraphrule{0pt}
\renewcommand\textflush{flushright}
\renewcommand\epigraphsize{\normalsize\itshape}

% Split at comas for long formulas
\newcommand{\splitatcommas}[1]{%
	\begingroup
	\ifnum\mathcode`,="8000
	\else
	\begingroup\lccode`~=`, \lowercase{\endgroup
		\edef~{\mathchar\the\mathcode`, \penalty0 \noexpand\hspace{0pt plus 1em}}%
	}\mathcode`,="8000
	\fi
	#1%
	\endgroup
}

% some macros to make it more readable
\gdef\theV{\includegraphics[height=1.1\fontcharht\font`V]{../../../../website/src/main/jbake/assets/images/MessageVortexLogo}}
\gdef\MessageVortex{\texorpdfstring{\emph{MessageVortex}}{MessageVortex}}
\gdef\VortexMessage{\emph{\defref{VortexMessage}}}
\gdef\VortexMessages{\texorpdfstring{\emph{\defref{VortexMessage}s}}{VortexMessages}}
\gdef\VortexNode{\emph{\defref{VortexNode}}}
\gdef\VortexNodes{\emph{\defref{VortexNode}s}}

% quoted environment
\usepackage{libertine}
\newcommand*\quotefont{\fontfamily{LinuxLibertineT-LF}}
\usepackage{etoolbox}
\usepackage{framed}
\newcommand*\quotesize{60} % if quote size changes, need a way to make shifts relative
% Make commands for the quotes
\newcommand*{\openquote}
{\tikz[remember picture,overlay,xshift=-4ex,yshift=-2.5ex]
	\node (OQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont``};\kern0pt}
\newcommand*{\closequote}[1]
{\tikz[remember picture,overlay,xshift=4ex,yshift={#1}]
	\node (CQ) {\quotefont\fontsize{\quotesize}{\quotesize}\selectfont''};}
% select a colour for the shading
\colorlet{shadecolor}{Azure}
\newcommand*\shadedauthorformat{\emph} % define format for the author argument
% Now a command to allow left, right and centre alignment of the author
\newcommand*\authoralign[1]{%
\if#1l
\def\authorfill{}\def\quotefill{\hfill}
\else
\if#1r
\def\authorfill{\hfill}\def\quotefill{}
\else
\if#1c
\gdef\authorfill{\hfill}\def\quotefill{\hfill}
\else\typeout{Invalid option}
\fi
\fi
\fi}
% wrap everything in its own environment which takes one argument (author) and one optional argument
% specifying the alignment [l, r or c]
%
\newenvironment{shadequote}[2][l]%
{\authoralign{#1}%
\ifblank{#2}%
{\def\shadequoteauthor{}\def\yshift{-2ex}\def\quotefill{\hfill}}%
{\def\shadequoteauthor{\par\authorfill\shadedauthorformat{#2}}\def\yshift{2ex}}%
\begin{snugshade}\begin{quote}\openquote}%
{\shadequoteauthor\quotefill\closequote{\yshift}\end{quote}\end{snugshade}}

% Allow byte field graphs
\usepackage{bytefield}


% Allow unbreakable hyphens
\usepackage[shortcuts]{extdash}

% set numbering for subsubsections
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}

% highlighting
\usepackage[bordercolor=white,backgroundcolor=gray!30,linecolor=black,colorinlistoftodos]{todonotes}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}

% allow clever references
\usepackage{cleveref}

\gdef\shadowshift{-3pt}
\definecolor{operationcolor}{RGB}{255,226,226}
\definecolor{endoperationcolor}{RGB}{255,255,226}
\definecolor{atomicopcolor}{RGB}{217,248,217}
\definecolor{senderkeycolor}{RGB}{159, 216, 255 }
\definecolor{payloadcolor}{RGB}{233,45,64}
\definecolor{peerkeycolor}{RGB}{217,248, 217}
\definecolor{hostkeycolor}{RGB}{190,217, 232}
\definecolor{layercolor}{RGB}{190,217, 232}
\definecolor{nodecolor}{RGB}{132, 151, 176}
\definecolor{startnodecolor}{RGB}{192, 151, 176}
\definecolor{endnodecolor}{RGB}{132, 211, 176}
\definecolor{nodeshadow}{RGB}{107, 107, 107}
\definecolor{hostIdentitycolor}{RGB}{255, 226, 226 }
\definecolor{transportcolor}{RGB}{220,20,20}
\definecolor{flowColor}{RGB}{ 79,136, 187}
\definecolor{flowBorderColor}{RGB}{ 79,116, 167}
\definecolor{unrelatedcolor}{RGB}{20,220,20}

\graphicspath{{./}{inc/}{../../../../website/src/main/jbake/assets/images/}{../../../../../website/src/main/jbake/assets/images/}}

\makeatletter
\patchcmd{\backmatter}
{\@mainmatterfalse}
{\@mainmatterfalse}
{}
{}
\makeatother

\begin{document}%
%
\frontmatter%
\input{inc/parts/00_a_title.inc.tex}
\input{inc/parts/00_b_toc.inc.tex}
\mainmatter
\startcontents
\input{inc/parts/01_intro.inc.tex}
\input{inc/parts/02_concepts.inc.tex}
\input{inc/parts/03_systems.inc.tex}
\input{inc/parts/04_messagevortex.inc.tex}
\input{inc/parts/05_implementation.inc.tex}
\input{inc/parts/06_operation.inc.tex}
\input{inc/parts/07_analysis.inc.tex}
\input{inc/parts/08_discussion.inc.tex}
\appendix

\input{inc/parts/AA_appendix.inc.tex}
\end{document}