developer.texi 377 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476
  1. @c ***********************************************************************
  2. @node GNUnet Developer Handbook
  3. @chapter GNUnet Developer Handbook
  4. This book is intended to be an introduction for programmers that want to
  5. extend the GNUnet framework. GNUnet is more than a simple peer-to-peer
  6. application.
  7. For developers, GNUnet is:
  8. @itemize @bullet
  9. @item developed by a community that believes in the GNU philosophy
  10. @item Free Software (Free as in Freedom), licensed under the
  11. GNU Affero General Public License
  12. (@uref{https://www.gnu.org/licenses/licenses.html#AGPL})
  13. @item A set of standards, including coding conventions and
  14. architectural rules
  15. @item A set of layered protocols, both specifying the communication
  16. between peers as well as the communication between components
  17. of a single peer
  18. @item A set of libraries with well-defined APIs suitable for
  19. writing extensions
  20. @end itemize
  21. In particular, the architecture specifies that a peer consists of many
  22. processes communicating via protocols. Processes can be written in almost
  23. any language.
  24. @code{C}, @code{Java} and @code{Guile} APIs exist for accessing existing
  25. services and for writing extensions.
  26. It is possible to write extensions in other languages by
  27. implementing the necessary IPC protocols.
  28. GNUnet can be extended and improved along many possible dimensions, and
  29. anyone interested in Free Software and Freedom-enhancing Networking is
  30. welcome to join the effort. This Developer Handbook attempts to provide
  31. an initial introduction to some of the key design choices and central
  32. components of the system.
  33. This part of the GNUnet documentation is far from complete,
  34. and we welcome informed contributions, be it in the form of
  35. new chapters, sections or insightful comments.
  36. @menu
  37. * Developer Introduction::
  38. * Internal dependencies::
  39. * Code overview::
  40. * System Architecture::
  41. * Subsystem stability::
  42. * Naming conventions and coding style guide::
  43. * Build-system::
  44. * Developing extensions for GNUnet using the gnunet-ext template::
  45. * Writing testcases::
  46. * Building GNUnet and its dependencies::
  47. * TESTING library::
  48. * Performance regression analysis with Gauger::
  49. * TESTBED Subsystem::
  50. * libgnunetutil::
  51. * Automatic Restart Manager (ARM)::
  52. * TRANSPORT Subsystem::
  53. * NAT library::
  54. * Distance-Vector plugin::
  55. * SMTP plugin::
  56. * Bluetooth plugin::
  57. * WLAN plugin::
  58. * ATS Subsystem::
  59. * CORE Subsystem::
  60. * CADET Subsystem::
  61. * NSE Subsystem::
  62. * HOSTLIST Subsystem::
  63. * IDENTITY Subsystem::
  64. * NAMESTORE Subsystem::
  65. * PEERINFO Subsystem::
  66. * PEERSTORE Subsystem::
  67. * SET Subsystem::
  68. * SETI Subsystem::
  69. * SETU Subsystem::
  70. * STATISTICS Subsystem::
  71. * Distributed Hash Table (DHT)::
  72. * GNU Name System (GNS)::
  73. * GNS Namecache::
  74. * REVOCATION Subsystem::
  75. * File-sharing (FS) Subsystem::
  76. * REGEX Subsystem::
  77. * REST Subsystem::
  78. * RPS Subsystem::
  79. @end menu
  80. @node Developer Introduction
  81. @section Developer Introduction
  82. This Developer Handbook is intended as first introduction to GNUnet for
  83. new developers that want to extend the GNUnet framework. After the
  84. introduction, each of the GNUnet subsystems (directories in the
  85. @file{src/} tree) is (supposed to be) covered in its own chapter. In
  86. addition to this documentation, GNUnet developers should be aware of the
  87. services available on the GNUnet server to them.
  88. New developers can have a look a the @uref{https://docs.gnunet.org/tutorial/gnunet-tutorial.html, GNUnet C tutorial}.
  89. @c ** FIXME: Link to files in source, not online.
  90. @c ** FIXME: Where is the Java tutorial?
  91. In addition to the GNUnet Reference Documentation you are reading,
  92. the GNUnet server at @uref{https://gnunet.org} contains
  93. various resources for GNUnet developers and those
  94. who aspire to become regular contributors.
  95. They are all conveniently reachable via the "Developer"
  96. entry in the navigation menu. Some additional tools (such as continuous
  97. integration) require a special developer access to perform certain
  98. operations. If you want (or require) access, you should contact
  99. GNUnet's maintainers.
  100. @c FIXME: A good part of this belongs on the website or should be
  101. @c extended in subsections explaining usage of this. A simple list
  102. @c is just taking space people have to read.
  103. The developer services on the GNUnet project infrastructure are:
  104. @itemize @bullet
  105. @item The version control system (git) keeps our code and enables
  106. distributed development.
  107. It is publicly accessible at @uref{https://git.gnunet.org/}.
  108. Only developers with write access can commit code, everyone else is
  109. encouraged to submit patches to the GNUnet-developers mailinglist:
  110. @uref{https://lists.gnu.org/mailman/listinfo/gnunet-developers, https://lists.gnu.org/mailman/listinfo/gnunet-developers}
  111. @item The bugtracking system (Mantis).
  112. We use it to track feature requests, open bug reports and their
  113. resolutions.
  114. It can be accessed at
  115. @uref{https://bugs.gnunet.org/, https://bugs.gnunet.org/}.
  116. Anyone can report bugs.
  117. @item Continuous integration (Buildbot).
  118. Used to build gnunet and its websites upon new commits.
  119. It can be accessed at
  120. @uref{https://buildbot.gnunet.org/, https://buildbot.gnunet.org/}.
  121. Anyone can see the builds.
  122. @item Regularly we make use of static analysis tools.
  123. Note that not everything that is flagged by the
  124. analysis is a bug, sometimes even good code can be marked as possibly
  125. problematic. Nevertheless, developers are encouraged to at least be
  126. aware of all issues in their code that are listed.
  127. @c @item We use Gauger for automatic performance regression visualization.
  128. @c FIXME: LINK!
  129. @c Details on how to use Gauger are here.
  130. @end itemize
  131. @c ***********************************************************************
  132. @menu
  133. * Project overview::
  134. @end menu
  135. @node Project overview
  136. @subsection Project overview
  137. The GNUnet project consists at this point of several sub-projects. This
  138. section is supposed to give an initial overview about the various
  139. sub-projects. Note that this description also lists projects that are far
  140. from complete, including even those that have literally not a single line
  141. of code in them yet.
  142. GNUnet sub-projects in order of likely relevance are currently:
  143. @table @asis
  144. @item @command{gnunet}
  145. Core of the P2P framework, including file-sharing, VPN and
  146. chat applications; this is what the Developer Handbook covers mostly
  147. @item @command{gnunet-gtk}
  148. Gtk+-based user interfaces, including:
  149. @itemize @bullet
  150. @item @command{gnunet-fs-gtk} (file-sharing),
  151. @item @command{gnunet-statistics-gtk} (statistics over time),
  152. @item @command{gnunet-peerinfo-gtk}
  153. (information about current connections and known peers),
  154. @item @command{gnunet-namestore-gtk} (GNS record editor),
  155. @item @command{gnunet-conversation-gtk} (voice chat GUI) and
  156. @item @command{gnunet-setup} (setup tool for "everything")
  157. @end itemize
  158. @item @command{gnunet-fuse}
  159. Mounting directories shared via GNUnet's file-sharing
  160. on GNU/Linux distributions
  161. @item @command{gnunet-update}
  162. Installation and update tool
  163. @item @command{gnunet-ext}
  164. Template for starting 'external' GNUnet projects
  165. @item @command{gnunet-java}
  166. Java APIs for writing GNUnet services and applications
  167. @item @command{gnunet-java-ext}
  168. @item @command{eclectic}
  169. Code to run GNUnet nodes on testbeds for research, development,
  170. testing and evaluation
  171. @c ** FIXME: Solve the status and location of gnunet-qt
  172. @item @command{gnunet-qt}
  173. Qt-based GNUnet GUI (is it deprecated?)
  174. @item @command{gnunet-cocoa}
  175. cocoa-based GNUnet GUI (is it deprecated?)
  176. @item @command{gnunet-guile}
  177. Guile bindings for GNUnet
  178. @item @command{gnunet-python}
  179. Python bindings for GNUnet
  180. @end table
  181. We are also working on various supporting libraries and tools:
  182. @c ** FIXME: What about gauger, and what about libmwmodem?
  183. @table @asis
  184. @item @command{libextractor}
  185. GNU libextractor (meta data extraction)
  186. @item @command{libmicrohttpd}
  187. GNU libmicrohttpd (embedded HTTP(S) server library)
  188. @item @command{gauger}
  189. Tool for performance regression analysis
  190. @item @command{monkey}
  191. Tool for automated debugging of distributed systems
  192. @item @command{libmwmodem}
  193. Library for accessing satellite connection quality reports
  194. @item @command{libgnurl}
  195. gnURL (feature-restricted variant of cURL/libcurl)
  196. @item @command{www}
  197. the gnunet.org website (Jinja2 based)
  198. @item @command{bibliography}
  199. Our collected bibliography, papers, references, and so forth
  200. @item @command{gnunet-videos-}
  201. Videos about and around GNUnet activities
  202. @end table
  203. Finally, there are various external projects (see links for a list of
  204. those that have a public website) which build on top of the GNUnet
  205. framework.
  206. @c ***********************************************************************
  207. @node Internal dependencies
  208. @section Internal dependencies
  209. This section tries to give an overview of what processes a typical GNUnet
  210. peer running a particular application would consist of. All of the
  211. processes listed here should be automatically started by
  212. @command{gnunet-arm -s}.
  213. The list is given as a rough first guide to users for failure diagnostics.
  214. Ideally, end-users should never have to worry about these internal
  215. dependencies.
  216. In terms of internal dependencies, a minimum file-sharing system consists
  217. of the following GNUnet processes (in order of dependency):
  218. @itemize @bullet
  219. @item gnunet-service-arm
  220. @item gnunet-service-resolver (required by all)
  221. @item gnunet-service-statistics (required by all)
  222. @item gnunet-service-peerinfo
  223. @item gnunet-service-transport (requires peerinfo)
  224. @item gnunet-service-core (requires transport)
  225. @item gnunet-daemon-hostlist (requires core)
  226. @item gnunet-daemon-topology (requires hostlist, peerinfo)
  227. @item gnunet-service-datastore
  228. @item gnunet-service-dht (requires core)
  229. @item gnunet-service-identity
  230. @item gnunet-service-fs (requires identity, mesh, dht, datastore, core)
  231. @end itemize
  232. @noindent
  233. A minimum VPN system consists of the following GNUnet processes (in
  234. order of dependency):
  235. @itemize @bullet
  236. @item gnunet-service-arm
  237. @item gnunet-service-resolver (required by all)
  238. @item gnunet-service-statistics (required by all)
  239. @item gnunet-service-peerinfo
  240. @item gnunet-service-transport (requires peerinfo)
  241. @item gnunet-service-core (requires transport)
  242. @item gnunet-daemon-hostlist (requires core)
  243. @item gnunet-service-dht (requires core)
  244. @item gnunet-service-mesh (requires dht, core)
  245. @item gnunet-service-dns (requires dht)
  246. @item gnunet-service-regex (requires dht)
  247. @item gnunet-service-vpn (requires regex, dns, mesh, dht)
  248. @end itemize
  249. @noindent
  250. A minimum GNS system consists of the following GNUnet processes (in
  251. order of dependency):
  252. @itemize @bullet
  253. @item gnunet-service-arm
  254. @item gnunet-service-resolver (required by all)
  255. @item gnunet-service-statistics (required by all)
  256. @item gnunet-service-peerinfo
  257. @item gnunet-service-transport (requires peerinfo)
  258. @item gnunet-service-core (requires transport)
  259. @item gnunet-daemon-hostlist (requires core)
  260. @item gnunet-service-dht (requires core)
  261. @item gnunet-service-mesh (requires dht, core)
  262. @item gnunet-service-dns (requires dht)
  263. @item gnunet-service-regex (requires dht)
  264. @item gnunet-service-vpn (requires regex, dns, mesh, dht)
  265. @item gnunet-service-identity
  266. @item gnunet-service-namestore (requires identity)
  267. @item gnunet-service-gns (requires vpn, dns, dht, namestore, identity)
  268. @end itemize
  269. @c ***********************************************************************
  270. @node Code overview
  271. @section Code overview
  272. This section gives a brief overview of the GNUnet source code.
  273. Specifically, we sketch the function of each of the subdirectories in
  274. the @file{gnunet/src/} directory. The order given is roughly bottom-up
  275. (in terms of the layers of the system).
  276. @table @asis
  277. @item @file{util/} --- libgnunetutil
  278. Library with general utility functions, all
  279. GNUnet binaries link against this library. Anything from memory
  280. allocation and data structures to cryptography and inter-process
  281. communication. The goal is to provide an OS-independent interface and
  282. more 'secure' or convenient implementations of commonly used primitives.
  283. The API is spread over more than a dozen headers, developers should study
  284. those closely to avoid duplicating existing functions.
  285. @pxref{libgnunetutil}.
  286. @item @file{hello/} --- libgnunethello
  287. HELLO messages are used to
  288. describe under which addresses a peer can be reached (for example,
  289. protocol, IP, port). This library manages parsing and generating of HELLO
  290. messages.
  291. @item @file{block/} --- libgnunetblock
  292. The DHT and other components of GNUnet
  293. store information in units called 'blocks'. Each block has a type and the
  294. type defines a particular format and how that binary format is to be
  295. linked to a hash code (the key for the DHT and for databases). The block
  296. library is a wrapper around block plugins which provide the necessary
  297. functions for each block type.
  298. @item @file{statistics/} --- statistics service
  299. The statistics service enables associating
  300. values (of type uint64_t) with a component name and a string. The main
  301. uses is debugging (counting events), performance tracking and user
  302. entertainment (what did my peer do today?).
  303. @item @file{arm/} --- Automatic Restart Manager (ARM)
  304. The automatic-restart-manager (ARM) service
  305. is the GNUnet master service. Its role is to start gnunet-services, to
  306. re-start them when they crashed and finally to shut down the system when
  307. requested.
  308. @item @file{peerinfo/} --- peerinfo service
  309. The peerinfo service keeps track of which peers are known
  310. to the local peer and also tracks the validated addresses for each peer
  311. (in the form of a HELLO message) for each of those peers. The peer is not
  312. necessarily connected to all peers known to the peerinfo service.
  313. Peerinfo provides persistent storage for peer identities --- peers are
  314. not forgotten just because of a system restart.
  315. @item @file{datacache/} --- libgnunetdatacache
  316. The datacache library provides (temporary) block storage for the DHT.
  317. Existing plugins can store blocks in Sqlite, Postgres or MySQL databases.
  318. All data stored in the cache is lost when the peer is stopped or
  319. restarted (datacache uses temporary tables).
  320. @item @file{datastore/} --- datastore service
  321. The datastore service stores file-sharing blocks in
  322. databases for extended periods of time. In contrast to the datacache, data
  323. is not lost when peers restart. However, quota restrictions may still
  324. cause old, expired or low-priority data to be eventually discarded.
  325. Existing plugins can store blocks in Sqlite, Postgres or MySQL databases.
  326. @item @file{template/} --- service template
  327. Template for writing a new service. Does nothing.
  328. @item @file{ats/} --- Automatic Transport Selection
  329. The automatic transport selection (ATS) service
  330. is responsible for deciding which address (i.e.
  331. which transport plugin) should be used for communication with other peers,
  332. and at what bandwidth.
  333. @item @file{nat/} --- libgnunetnat
  334. Library that provides basic functions for NAT traversal.
  335. The library supports NAT traversal with
  336. manual hole-punching by the user, UPnP and ICMP-based autonomous NAT
  337. traversal. The library also includes an API for testing if the current
  338. configuration works and the @code{gnunet-nat-server} which provides an
  339. external service to test the local configuration.
  340. @item @file{fragmentation/} --- libgnunetfragmentation
  341. Some transports (UDP and WLAN, mostly) have restrictions on the maximum
  342. transfer unit (MTU) for packets. The fragmentation library can be used to
  343. break larger packets into chunks of at most 1k and transmit the resulting
  344. fragments reliably (with acknowledgment, retransmission, timeouts,
  345. etc.).
  346. @item @file{transport/} --- transport service
  347. The transport service is responsible for managing the
  348. basic P2P communication. It uses plugins to support P2P communication
  349. over TCP, UDP, HTTP, HTTPS and other protocols.The transport service
  350. validates peer addresses, enforces bandwidth restrictions, limits the
  351. total number of connections and enforces connectivity restrictions (i.e.
  352. friends-only).
  353. @item @file{peerinfo-tool/} --- gnunet-peerinfo
  354. This directory contains the gnunet-peerinfo binary which can be used to
  355. inspect the peers and HELLOs known to the peerinfo service.
  356. @item @file{core/}
  357. The core service is responsible for establishing encrypted, authenticated
  358. connections with other peers, encrypting and decrypting messages and
  359. forwarding messages to higher-level services that are interested in them.
  360. @item @file{testing/} --- libgnunettesting
  361. The testing library allows starting (and stopping) peers
  362. for writing testcases.
  363. It also supports automatic generation of configurations for peers
  364. ensuring that the ports and paths are disjoint. libgnunettesting is also
  365. the foundation for the testbed service
  366. @item @file{testbed/} --- testbed service
  367. The testbed service is used for creating small or large scale deployments
  368. of GNUnet peers for evaluation of protocols.
  369. It facilitates peer deployments on multiple
  370. hosts (for example, in a cluster) and establishing various network
  371. topologies (both underlay and overlay).
  372. @item @file{nse/} --- Network Size Estimation
  373. The network size estimation (NSE) service
  374. implements a protocol for (securely) estimating the current size of the
  375. P2P network.
  376. @item @file{dht/} --- distributed hash table
  377. The distributed hash table (DHT) service provides a
  378. distributed implementation of a hash table to store blocks under hash
  379. keys in the P2P network.
  380. @item @file{hostlist/} --- hostlist service
  381. The hostlist service allows learning about
  382. other peers in the network by downloading HELLO messages from an HTTP
  383. server, can be configured to run such an HTTP server and also implements
  384. a P2P protocol to advertise and automatically learn about other peers
  385. that offer a public hostlist server.
  386. @item @file{topology/} --- topology service
  387. The topology service is responsible for
  388. maintaining the mesh topology. It tries to maintain connections to friends
  389. (depending on the configuration) and also tries to ensure that the peer
  390. has a decent number of active connections at all times. If necessary, new
  391. connections are added. All peers should run the topology service,
  392. otherwise they may end up not being connected to any other peer (unless
  393. some other service ensures that core establishes the required
  394. connections). The topology service also tells the transport service which
  395. connections are permitted (for friend-to-friend networking)
  396. @item @file{fs/} --- file-sharing
  397. The file-sharing (FS) service implements GNUnet's
  398. file-sharing application. Both anonymous file-sharing (using gap) and
  399. non-anonymous file-sharing (using dht) are supported.
  400. @item @file{cadet/} --- cadet service
  401. The CADET service provides a general-purpose routing abstraction to create
  402. end-to-end encrypted tunnels in mesh networks. We wrote a paper
  403. documenting key aspects of the design.
  404. @item @file{tun/} --- libgnunettun
  405. Library for building IPv4, IPv6 packets and creating
  406. checksums for UDP, TCP and ICMP packets. The header
  407. defines C structs for common Internet packet formats and in particular
  408. structs for interacting with TUN (virtual network) interfaces.
  409. @item @file{mysql/} --- libgnunetmysql
  410. Library for creating and executing prepared MySQL
  411. statements and to manage the connection to the MySQL database.
  412. Essentially a lightweight wrapper for the interaction between GNUnet
  413. components and libmysqlclient.
  414. @item @file{dns/}
  415. Service that allows intercepting and modifying DNS requests of
  416. the local machine. Currently used for IPv4-IPv6 protocol translation
  417. (DNS-ALG) as implemented by "pt/" and for the GNUnet naming system. The
  418. service can also be configured to offer an exit service for DNS traffic.
  419. @item @file{vpn/} --- VPN service
  420. The virtual public network (VPN) service provides a virtual
  421. tunnel interface (VTUN) for IP routing over GNUnet.
  422. Needs some other peers to run an "exit" service to work.
  423. Can be activated using the "gnunet-vpn" tool or integrated with DNS using
  424. the "pt" daemon.
  425. @item @file{exit/}
  426. Daemon to allow traffic from the VPN to exit this
  427. peer to the Internet or to specific IP-based services of the local peer.
  428. Currently, an exit service can only be restricted to IPv4 or IPv6, not to
  429. specific ports and or IP address ranges. If this is not acceptable,
  430. additional firewall rules must be added manually. exit currently only
  431. works for normal UDP, TCP and ICMP traffic; DNS queries need to leave the
  432. system via a DNS service.
  433. @item @file{pt/}
  434. protocol translation daemon. This daemon enables 4-to-6,
  435. 6-to-4, 4-over-6 or 6-over-4 transitions for the local system. It
  436. essentially uses "DNS" to intercept DNS replies and then maps results to
  437. those offered by the VPN, which then sends them using mesh to some daemon
  438. offering an appropriate exit service.
  439. @item @file{identity/}
  440. Management of egos (alter egos) of a user; identities are
  441. essentially named ECC private keys and used for zones in the GNU name
  442. system and for namespaces in file-sharing, but might find other uses later
  443. @item @file{revocation/}
  444. Key revocation service, can be used to revoke the
  445. private key of an identity if it has been compromised
  446. @item @file{namecache/}
  447. Cache for resolution results for the GNU name system;
  448. data is encrypted and can be shared among users,
  449. loss of the data should ideally only result in a
  450. performance degradation (persistence not required)
  451. @item @file{namestore/}
  452. Database for the GNU name system with per-user private information,
  453. persistence required
  454. @item @file{gns/}
  455. GNU name system, a GNU approach to DNS and PKI.
  456. @item @file{dv/}
  457. A plugin for distance-vector (DV)-based routing.
  458. DV consists of a service and a transport plugin to provide peers
  459. with the illusion of a direct P2P connection for connections
  460. that use multiple (typically up to 3) hops in the actual underlay network.
  461. @item @file{regex/}
  462. Service for the (distributed) evaluation of regular expressions.
  463. @item @file{scalarproduct/}
  464. The scalar product service offers an API to perform a secure multiparty
  465. computation which calculates a scalar product between two peers
  466. without exposing the private input vectors of the peers to each other.
  467. @item @file{consensus/}
  468. The consensus service will allow a set of peers to agree
  469. on a set of values via a distributed set union computation.
  470. @item @file{reclaim/}
  471. A decentralized personal data sharing service used to realize a decentralized
  472. identity provider. Supports OpenID Connect. See also @uref{https://reclaim.gnunet.org}.
  473. @item @file{rest/}
  474. The rest API allows access to GNUnet services using RESTful interaction.
  475. The services provide plugins that can exposed by the rest server.
  476. @c FIXME: Where did this disappear to?
  477. @c @item @file{experimentation/}
  478. @c The experimentation daemon coordinates distributed
  479. @c experimentation to evaluate transport and ATS properties.
  480. @end table
  481. @c ***********************************************************************
  482. @node System Architecture
  483. @section System Architecture
  484. @c FIXME: For those irritated by the textflow, we are missing images here,
  485. @c in the short term we should add them back, in the long term this should
  486. @c work without images or have images with alt-text.
  487. GNUnet developers like LEGOs. The blocks are indestructible, can be
  488. stacked together to construct complex buildings and it is generally easy
  489. to swap one block for a different one that has the same shape. GNUnet's
  490. architecture is based on LEGOs:
  491. @image{images/service_lego_block,5in,,picture of a LEGO block stack - 3 APIs upon IPC/network protocol provided by a service}
  492. This chapter documents the GNUnet LEGO system, also known as GNUnet's
  493. system architecture.
  494. The most common GNUnet component is a service. Services offer an API (or
  495. several, depending on what you count as "an API") which is implemented as
  496. a library. The library communicates with the main process of the service
  497. using a service-specific network protocol. The main process of the service
  498. typically doesn't fully provide everything that is needed --- it has holes
  499. to be filled by APIs to other services.
  500. A special kind of component in GNUnet are user interfaces and daemons.
  501. Like services, they have holes to be filled by APIs of other services.
  502. Unlike services, daemons do not implement their own network protocol and
  503. they have no API:
  504. @image{images/daemon_lego_block,5in,,A daemon in GNUnet is a component that does not offer an API for others to build upon}
  505. The GNUnet system provides a range of services, daemons and user
  506. interfaces, which are then combined into a layered GNUnet instance (also
  507. known as a peer).
  508. @image{images/service_stack,5in,,A GNUnet peer consists of many layers of services}
  509. Note that while it is generally possible to swap one service for another
  510. compatible service, there is often only one implementation. However,
  511. during development we often have a "new" version of a service in parallel
  512. with an "old" version. While the "new" version is not working, developers
  513. working on other parts of the service can continue their development by
  514. simply using the "old" service. Alternative design ideas can also be
  515. easily investigated by swapping out individual components. This is
  516. typically achieved by simply changing the name of the "BINARY" in the
  517. respective configuration section.
  518. Key properties of GNUnet services are that they must be separate
  519. processes and that they must protect themselves by applying tight error
  520. checking against the network protocol they implement (thereby achieving a
  521. certain degree of robustness).
  522. On the other hand, the APIs are implemented to tolerate failures of the
  523. service, isolating their host process from errors by the service. If the
  524. service process crashes, other services and daemons around it should not
  525. also fail, but instead wait for the service process to be restarted by
  526. ARM.
  527. @c ***********************************************************************
  528. @node Subsystem stability
  529. @section Subsystem stability
  530. This section documents the current stability of the various GNUnet
  531. subsystems. Stability here describes the expected degree of compatibility
  532. with future versions of GNUnet. For each subsystem we distinguish between
  533. compatibility on the P2P network level (communication protocol between
  534. peers), the IPC level (communication between the service and the service
  535. library) and the API level (stability of the API). P2P compatibility is
  536. relevant in terms of which applications are likely going to be able to
  537. communicate with future versions of the network. IPC communication is
  538. relevant for the implementation of language bindings that re-implement the
  539. IPC messages. Finally, API compatibility is relevant to developers that
  540. hope to be able to avoid changes to applications build on top of the APIs
  541. of the framework.
  542. The following table summarizes our current view of the stability of the
  543. respective protocols or APIs:
  544. @multitable @columnfractions .20 .20 .20 .20
  545. @headitem Subsystem @tab P2P @tab IPC @tab C API
  546. @item util @tab n/a @tab n/a @tab stable
  547. @item arm @tab n/a @tab stable @tab stable
  548. @item ats @tab n/a @tab unstable @tab testing
  549. @item block @tab n/a @tab n/a @tab stable
  550. @item cadet @tab testing @tab testing @tab testing
  551. @item consensus @tab experimental @tab experimental @tab experimental
  552. @item core @tab stable @tab stable @tab stable
  553. @item datacache @tab n/a @tab n/a @tab stable
  554. @item datastore @tab n/a @tab stable @tab stable
  555. @item dht @tab stable @tab stable @tab stable
  556. @item dns @tab stable @tab stable @tab stable
  557. @item dv @tab testing @tab testing @tab n/a
  558. @item exit @tab testing @tab n/a @tab n/a
  559. @item fragmentation @tab stable @tab n/a @tab stable
  560. @item fs @tab stable @tab stable @tab stable
  561. @item gns @tab stable @tab stable @tab stable
  562. @item hello @tab n/a @tab n/a @tab testing
  563. @item hostlist @tab stable @tab stable @tab n/a
  564. @item identity @tab stable @tab stable @tab n/a
  565. @item multicast @tab experimental @tab experimental @tab experimental
  566. @item mysql @tab stable @tab n/a @tab stable
  567. @item namestore @tab n/a @tab stable @tab stable
  568. @item nat @tab n/a @tab n/a @tab stable
  569. @item nse @tab stable @tab stable @tab stable
  570. @item peerinfo @tab n/a @tab stable @tab stable
  571. @item psyc @tab experimental @tab experimental @tab experimental
  572. @item pt @tab n/a @tab n/a @tab n/a
  573. @item regex @tab stable @tab stable @tab stable
  574. @item revocation @tab stable @tab stable @tab stable
  575. @item social @tab experimental @tab experimental @tab experimental
  576. @item statistics @tab n/a @tab stable @tab stable
  577. @item testbed @tab n/a @tab testing @tab testing
  578. @item testing @tab n/a @tab n/a @tab testing
  579. @item topology @tab n/a @tab n/a @tab n/a
  580. @item transport @tab experimental @tab experimental @tab experimental
  581. @item tun @tab n/a @tab n/a @tab stable
  582. @item vpn @tab testing @tab n/a @tab n/a
  583. @end multitable
  584. Here is a rough explanation of the values:
  585. @table @samp
  586. @item stable
  587. No incompatible changes are planned at this time; for IPC/APIs, if
  588. there are incompatible changes, they will be minor and might only require
  589. minimal changes to existing code; for P2P, changes will be avoided if at
  590. all possible for the 0.10.x-series
  591. @item testing
  592. No incompatible changes are
  593. planned at this time, but the code is still known to be in flux; so while
  594. we have no concrete plans, our expectation is that there will still be
  595. minor modifications; for P2P, changes will likely be extensions that
  596. should not break existing code
  597. @item unstable
  598. Changes are planned and will happen; however, they
  599. will not be totally radical and the result should still resemble what is
  600. there now; nevertheless, anticipated changes will break protocol/API
  601. compatibility
  602. @item experimental
  603. Changes are planned and the result may look nothing like
  604. what the API/protocol looks like today
  605. @item unknown
  606. Someone should think about where this subsystem headed
  607. @item n/a
  608. This subsystem does not have an API/IPC-protocol/P2P-protocol
  609. @end table
  610. @c ***********************************************************************
  611. @node Naming conventions and coding style guide
  612. @section Naming conventions and coding style guide
  613. Here you can find some rules to help you write code for GNUnet.
  614. @c ***********************************************************************
  615. @menu
  616. * Naming conventions::
  617. * Coding style::
  618. @end menu
  619. @node Naming conventions
  620. @subsection Naming conventions
  621. @c ***********************************************************************
  622. @menu
  623. * include files::
  624. * binaries::
  625. * logging::
  626. * configuration::
  627. * exported symbols::
  628. * private (library-internal) symbols (including structs and macros)::
  629. * testcases::
  630. * performance tests::
  631. * src/ directories::
  632. @end menu
  633. @node include files
  634. @subsubsection include files
  635. @itemize @bullet
  636. @item _lib: library without need for a process
  637. @item _service: library that needs a service process
  638. @item _plugin: plugin definition
  639. @item _protocol: structs used in network protocol
  640. @item exceptions:
  641. @itemize @bullet
  642. @item gnunet_config.h --- generated
  643. @item platform.h --- first included
  644. @item gnunet_common.h --- fundamental routines
  645. @item gnunet_directories.h --- generated
  646. @item gettext.h --- external library
  647. @end itemize
  648. @end itemize
  649. @c ***********************************************************************
  650. @node binaries
  651. @subsubsection binaries
  652. @itemize @bullet
  653. @item gnunet-service-xxx: service process (has listen socket)
  654. @item gnunet-daemon-xxx: daemon process (no listen socket)
  655. @item gnunet-helper-xxx[-yyy]: SUID helper for module xxx
  656. @item gnunet-yyy: command-line tool for end-users
  657. @item libgnunet_plugin_xxx_yyy.so: plugin for API xxx
  658. @item libgnunetxxx.so: library for API xxx
  659. @end itemize
  660. @c ***********************************************************************
  661. @node logging
  662. @subsubsection logging
  663. @itemize @bullet
  664. @item services and daemons use their directory name in
  665. @code{GNUNET_log_setup} (i.e. 'core') and log using
  666. plain 'GNUNET_log'.
  667. @item command-line tools use their full name in
  668. @code{GNUNET_log_setup} (i.e. 'gnunet-publish') and log using
  669. plain 'GNUNET_log'.
  670. @item service access libraries log using
  671. '@code{GNUNET_log_from}' and use '@code{DIRNAME-api}' for the
  672. component (i.e. 'core-api')
  673. @item pure libraries (without associated service) use
  674. '@code{GNUNET_log_from}' with the component set to their
  675. library name (without lib or '@file{.so}'),
  676. which should also be their directory name (i.e. '@file{nat}')
  677. @item plugins should use '@code{GNUNET_log_from}'
  678. with the directory name and the plugin name combined to produce
  679. the component name (i.e. 'transport-tcp').
  680. @item logging should be unified per-file by defining a
  681. @code{LOG} macro with the appropriate arguments,
  682. along these lines:
  683. @example
  684. #define LOG(kind,...)
  685. GNUNET_log_from (kind, "example-api",__VA_ARGS__)
  686. @end example
  687. @end itemize
  688. @c ***********************************************************************
  689. @node configuration
  690. @subsubsection configuration
  691. @itemize @bullet
  692. @item paths (that are substituted in all filenames) are in PATHS
  693. (have as few as possible)
  694. @item all options for a particular module (@file{src/MODULE})
  695. are under @code{[MODULE]}
  696. @item options for a plugin of a module
  697. are under @code{[MODULE-PLUGINNAME]}
  698. @end itemize
  699. @c ***********************************************************************
  700. @node exported symbols
  701. @subsubsection exported symbols
  702. @itemize @bullet
  703. @item must start with @code{GNUNET_modulename_} and be defined in
  704. @file{modulename.c}
  705. @item exceptions: those defined in @file{gnunet_common.h}
  706. @end itemize
  707. @c ***********************************************************************
  708. @node private (library-internal) symbols (including structs and macros)
  709. @subsubsection private (library-internal) symbols (including structs and macros)
  710. @itemize @bullet
  711. @item must NOT start with any prefix
  712. @item must not be exported in a way that linkers could use them or@ other
  713. libraries might see them via headers; they must be either
  714. declared/defined in C source files or in headers that are in the
  715. respective directory under @file{src/modulename/} and NEVER be declared
  716. in @file{src/include/}.
  717. @end itemize
  718. @node testcases
  719. @subsubsection testcases
  720. @itemize @bullet
  721. @item must be called @file{test_module-under-test_case-description.c}
  722. @item "case-description" maybe omitted if there is only one test
  723. @end itemize
  724. @c ***********************************************************************
  725. @node performance tests
  726. @subsubsection performance tests
  727. @itemize @bullet
  728. @item must be called @file{perf_module-under-test_case-description.c}
  729. @item "case-description" maybe omitted if there is only one performance
  730. test
  731. @item Must only be run if @code{HAVE_BENCHMARKS} is satisfied
  732. @end itemize
  733. @c ***********************************************************************
  734. @node src/ directories
  735. @subsubsection src/ directories
  736. @itemize @bullet
  737. @item gnunet-NAME: end-user applications (i.e., gnunet-search, gnunet-arm)
  738. @item gnunet-service-NAME: service processes with accessor library (i.e.,
  739. gnunet-service-arm)
  740. @item libgnunetNAME: accessor library (_service.h-header) or standalone
  741. library (_lib.h-header)
  742. @item gnunet-daemon-NAME: daemon process without accessor library (i.e.,
  743. gnunet-daemon-hostlist) and no GNUnet management port
  744. @item libgnunet_plugin_DIR_NAME: loadable plugins (i.e.,
  745. libgnunet_plugin_transport_tcp)
  746. @end itemize
  747. @cindex Coding style
  748. @node Coding style
  749. @subsection Coding style
  750. @c XXX: Adjust examples to GNU Standards!
  751. @itemize @bullet
  752. @item We follow the GNU Coding Standards (@pxref{Top, The GNU Coding Standards,, standards, The GNU Coding Standards});
  753. @item Indentation is done with spaces, two per level, no tabs; specific (incomplete!) indentation rules are provided in an @code{uncrustify} configuration file (in ``contrib/``) and enforced by Git hooks;
  754. @item C99 struct initialization is fine and generally encouraged (but not required);
  755. @item As in all good C code, we care about symbol space pollution and thus use @code{static} to limit the scope where possible, even in the compilation unit that contains @code{main};
  756. @item declare only one variable per line, for example:
  757. @noindent
  758. instead of
  759. @example
  760. int i,j;
  761. @end example
  762. @noindent
  763. write:
  764. @example
  765. int i;
  766. int j;
  767. @end example
  768. @c TODO: include actual example from a file in source
  769. @noindent
  770. This helps keep diffs small and forces developers to think precisely about
  771. the type of every variable.
  772. Note that @code{char *} is different from @code{const char*} and
  773. @code{int} is different from @code{unsigned int} or @code{uint32_t}.
  774. Each variable type should be chosen with care.
  775. @item While @code{goto} should generally be avoided, having a
  776. @code{goto} to the end of a function to a block of clean up
  777. statements (free, close, etc.) can be acceptable.
  778. @item Conditions should be written with constants on the left (to avoid
  779. accidental assignment) and with the @code{true} target being either the
  780. @code{error} case or the significantly simpler continuation. For example:
  781. @example
  782. if (0 != stat ("filename,"
  783. &sbuf))
  784. @{
  785. error();
  786. @}
  787. else
  788. @{
  789. /* handle normal case here */
  790. @}
  791. @end example
  792. @noindent
  793. instead of
  794. @example
  795. if (stat ("filename," &sbuf) == 0) @{
  796. /* handle normal case here */
  797. @} else @{
  798. error();
  799. @}
  800. @end example
  801. @noindent
  802. If possible, the error clause should be terminated with a @code{return} (or
  803. @code{goto} to some cleanup routine) and in this case, the @code{else} clause
  804. should be omitted:
  805. @example
  806. if (0 != stat ("filename",
  807. &sbuf))
  808. @{
  809. error();
  810. return;
  811. @}
  812. /* handle normal case here */
  813. @end example
  814. This serves to avoid deep nesting. The 'constants on the left' rule
  815. applies to all constants (including. @code{GNUNET_SCHEDULER_NO_TASK}),
  816. NULL, and enums). With the two above rules (constants on left, errors in
  817. 'true' branch), there is only one way to write most branches correctly.
  818. @item Combined assignments and tests are allowed if they do not hinder
  819. code clarity. For example, one can write:
  820. @example
  821. if (NULL == (value = lookup_function()))
  822. @{
  823. error();
  824. return;
  825. @}
  826. @end example
  827. @item Use @code{break} and @code{continue} wherever possible to avoid
  828. deep(er) nesting. Thus, we would write:
  829. @example
  830. next = head;
  831. while (NULL != (pos = next))
  832. @{
  833. next = pos->next;
  834. if (! should_free (pos))
  835. continue;
  836. GNUNET_CONTAINER_DLL_remove (head,
  837. tail,
  838. pos);
  839. GNUNET_free (pos);
  840. @}
  841. @end example
  842. instead of
  843. @example
  844. next = head; while (NULL != (pos = next)) @{
  845. next = pos->next;
  846. if (should_free (pos)) @{
  847. /* unnecessary nesting! */
  848. GNUNET_CONTAINER_DLL_remove (head, tail, pos);
  849. GNUNET_free (pos);
  850. @}
  851. @}
  852. @end example
  853. @item We primarily use @code{for} and @code{while} loops.
  854. A @code{while} loop is used if the method for advancing in the loop is
  855. not a straightforward increment operation. In particular, we use:
  856. @example
  857. next = head;
  858. while (NULL != (pos = next))
  859. @{
  860. next = pos->next;
  861. if (! should_free (pos))
  862. continue;
  863. GNUNET_CONTAINER_DLL_remove (head,
  864. tail,
  865. pos);
  866. GNUNET_free (pos);
  867. @}
  868. @end example
  869. to free entries in a list (as the iteration changes the structure of the
  870. list due to the free; the equivalent @code{for} loop does no longer
  871. follow the simple @code{for} paradigm of @code{for(INIT;TEST;INC)}).
  872. However, for loops that do follow the simple @code{for} paradigm we do
  873. use @code{for}, even if it involves linked lists:
  874. @example
  875. /* simple iteration over a linked list */
  876. for (pos = head;
  877. NULL != pos;
  878. pos = pos->next)
  879. @{
  880. use (pos);
  881. @}
  882. @end example
  883. @item The first argument to all higher-order functions in GNUnet must be
  884. declared to be of type @code{void *} and is reserved for a closure. We do
  885. not use inner functions, as trampolines would conflict with setups that
  886. use non-executable stacks.
  887. The first statement in a higher-order function, which unusually should
  888. be part of the variable declarations, should assign the
  889. @code{cls} argument to the precise expected type. For example:
  890. @example
  891. int
  892. callback (void *cls,
  893. char *args)
  894. @{
  895. struct Foo *foo = cls;
  896. int other_variables;
  897. /* rest of function */
  898. @}
  899. @end example
  900. @item As shown in the example above, after the return type of a
  901. function there should be a break. Each parameter should
  902. be on a new line.
  903. @item It is good practice to write complex @code{if} expressions instead
  904. of using deeply nested @code{if} statements. However, except for addition
  905. and multiplication, all operators should use parens. This is fine:
  906. @example
  907. if ( (1 == foo) ||
  908. ( (0 == bar) &&
  909. (x != y) ) )
  910. return x;
  911. @end example
  912. However, this is not:
  913. @example
  914. if (1 == foo)
  915. return x;
  916. if (0 == bar && x != y)
  917. return x;
  918. @end example
  919. @noindent
  920. Note that splitting the @code{if} statement above is debatable as the
  921. @code{return x} is a very trivial statement. However, once the logic after
  922. the branch becomes more complicated (and is still identical), the "or"
  923. formulation should be used for sure.
  924. @item There should be two empty lines between the end of the function and
  925. the comments describing the following function. There should be a single
  926. empty line after the initial variable declarations of a function. If a
  927. function has no local variables, there should be no initial empty line. If
  928. a long function consists of several complex steps, those steps might be
  929. separated by an empty line (possibly followed by a comment describing the
  930. following step). The code should not contain empty lines in arbitrary
  931. places; if in doubt, it is likely better to NOT have an empty line (this
  932. way, more code will fit on the screen).
  933. @item When command-line arguments become too long (and would result in
  934. some particularly ugly @code{uncrustify} wrapping), we start all arguments
  935. on a new line. As a result, there must never be a new line within an
  936. argument declaration (i.e. between @code{struct} and the struct's name) or
  937. between the type and the variable). Example:
  938. @example
  939. struct GNUNET_TRANSPORT_CommunicatorHandle *
  940. GNUNET_TRANSPORT_communicator_connect (
  941. const struct GNUNET_CONFIGURATION_Handle *cfg,
  942. const char *config_section_name,
  943. const char *addr_prefix,
  944. ...);
  945. @end example
  946. Note that for short function names and arguments, the first argument
  947. does remain on the same line. Example:
  948. @example
  949. void
  950. fun (short i,
  951. short j);
  952. @end example
  953. @end itemize
  954. @c ***********************************************************************
  955. @node Build-system
  956. @section Build-system
  957. If you have code that is likely not to compile or build rules you might
  958. want to not trigger for most developers, use @code{if HAVE_EXPERIMENTAL}
  959. in your @file{Makefile.am}.
  960. Then it is OK to (temporarily) add non-compiling (or known-to-not-port)
  961. code.
  962. If you want to compile all testcases but NOT run them, run configure with
  963. the @code{--enable-test-suppression} option.
  964. If you want to run all testcases, including those that take a while, run
  965. configure with the @code{--enable-expensive-testcases} option.
  966. If you want to compile and run benchmarks, run configure with the
  967. @code{--enable-benchmarks} option.
  968. If you want to obtain code coverage results, run configure with the
  969. @code{--enable-coverage} option and run the @file{coverage.sh} script in
  970. the @file{contrib/} directory.
  971. @cindex gnunet-ext
  972. @node Developing extensions for GNUnet using the gnunet-ext template
  973. @section Developing extensions for GNUnet using the gnunet-ext template
  974. For developers who want to write extensions for GNUnet we provide the
  975. gnunet-ext template to provide an easy to use skeleton.
  976. gnunet-ext contains the build environment and template files for the
  977. development of GNUnet services, command line tools, APIs and tests.
  978. First of all you have to obtain gnunet-ext from git:
  979. @example
  980. git clone https://git.gnunet.org/gnunet-ext.git
  981. @end example
  982. The next step is to bootstrap and configure it. For configure you have to
  983. provide the path containing GNUnet with
  984. @code{--with-gnunet=/path/to/gnunet} and the prefix where you want the
  985. install the extension using @code{--prefix=/path/to/install}:
  986. @example
  987. ./bootstrap
  988. ./configure --prefix=/path/to/install --with-gnunet=/path/to/gnunet
  989. @end example
  990. When your GNUnet installation is not included in the default linker search
  991. path, you have to add @code{/path/to/gnunet} to the file
  992. @file{/etc/ld.so.conf} and run @code{ldconfig} or your add it to the
  993. environmental variable @code{LD_LIBRARY_PATH} by using
  994. @example
  995. export LD_LIBRARY_PATH=/path/to/gnunet/lib
  996. @end example
  997. @cindex writing testcases
  998. @node Writing testcases
  999. @section Writing testcases
  1000. Ideally, any non-trivial GNUnet code should be covered by automated
  1001. testcases. Testcases should reside in the same place as the code that is
  1002. being tested. The name of source files implementing tests should begin
  1003. with @code{test_} followed by the name of the file that contains
  1004. the code that is being tested.
  1005. Testcases in GNUnet should be integrated with the autotools build system.
  1006. This way, developers and anyone building binary packages will be able to
  1007. run all testcases simply by running @code{make check}. The final
  1008. testcases shipped with the distribution should output at most some brief
  1009. progress information and not display debug messages by default. The
  1010. success or failure of a testcase must be indicated by returning zero
  1011. (success) or non-zero (failure) from the main method of the testcase.
  1012. The integration with the autotools is relatively straightforward and only
  1013. requires modifications to the @file{Makefile.am} in the directory
  1014. containing the testcase. For a testcase testing the code in @file{foo.c}
  1015. the @file{Makefile.am} would contain the following lines:
  1016. @example
  1017. check_PROGRAMS = test_foo
  1018. TESTS = $(check_PROGRAMS)
  1019. test_foo_SOURCES = test_foo.c
  1020. test_foo_LDADD = $(top_builddir)/src/util/libgnunetutil.la
  1021. @end example
  1022. Naturally, other libraries used by the testcase may be specified in the
  1023. @code{LDADD} directive as necessary.
  1024. Often testcases depend on additional input files, such as a configuration
  1025. file. These support files have to be listed using the @code{EXTRA_DIST}
  1026. directive in order to ensure that they are included in the distribution.
  1027. Example:
  1028. @example
  1029. EXTRA_DIST = test_foo_data.conf
  1030. @end example
  1031. Executing @code{make check} will run all testcases in the current
  1032. directory and all subdirectories. Testcases can be compiled individually
  1033. by running @code{make test_foo} and then invoked directly using
  1034. @code{./test_foo}. Note that due to the use of plugins in GNUnet, it is
  1035. typically necessary to run @code{make install} before running any
  1036. testcases. Thus the canonical command @code{make check install} has to be
  1037. changed to @code{make install check} for GNUnet.
  1038. @c ***********************************************************************
  1039. @cindex Building GNUnet
  1040. @node Building GNUnet and its dependencies
  1041. @section Building GNUnet and its dependencies
  1042. In the following section we will outline how to build GNUnet and
  1043. some of its dependencies. We will assume a fair amount of knowledge
  1044. for building applications under UNIX-like systems. Furthermore we
  1045. assume that the build environment is sane and that you are aware of
  1046. any implications actions in this process could have.
  1047. Instructions here can be seen as notes for developers (an extension to
  1048. the 'HACKING' section in README) as well as package maintainers.
  1049. @b{Users should rely on the available binary packages.}
  1050. We will use Debian as an example Operating System environment. Substitute
  1051. accordingly with your own Operating System environment.
  1052. For the full list of dependencies, consult the appropriate, up-to-date
  1053. section in the @file{README} file.
  1054. @example
  1055. libgpgerror, libgcrypt, libnettle, libunbound, GnuTLS (with libunbound
  1056. support)
  1057. @end example
  1058. After we have build and installed those packages, we continue with
  1059. packages closer to GNUnet in this step: libgnurl (our libcurl fork),
  1060. GNU libmicrohttpd, and GNU libextractor. Again, if your package manager
  1061. provides one of these packages, use the packages provided from it
  1062. unless you have good reasons (package version too old, conflicts, etc).
  1063. We advise against compiling widely used packages such as GnuTLS
  1064. yourself if your OS provides a variant already unless you take care
  1065. of maintenance of the packages then.
  1066. In the optimistic case, this command will give you all the dependencies
  1067. on Debian, Debian derived systems or any Linux Operating System using
  1068. the apt package manager:
  1069. @example
  1070. sudo apt-get install libgnurl libmicrohttpd libextractor
  1071. @end example
  1072. From experience we know that at the very least libgnurl is not
  1073. available in some environments. You could substitute libgnurl
  1074. with libcurl, but we recommend to install libgnurl, as it gives
  1075. you a predefined libcurl with the small set GNUnet requires.
  1076. libgnurl has been developed to co-exist with libcurl installations,
  1077. installing it will cause no filename or namespace collisions.
  1078. @cindex libgnurl
  1079. @cindex compiling libgnurl
  1080. GNUnet and some of its function depend on a limited subset of cURL/libcurl.
  1081. Rather than trying to enforce a certain configuration on the world, we
  1082. opted to maintain a microfork of it that ensures that we can link
  1083. against the right set of features.
  1084. We called this specialized set of libcurl "libgnurl".
  1085. It is fully ABI compatible with libcurl and currently used by
  1086. GNUnet and some of its dependencies.
  1087. We download libgnurl and its digital signature from the GNU fileserver,
  1088. assuming @env{TMPDIR} exists.
  1089. @quotation
  1090. Note: TMPDIR might be @file{/tmp}, @env{TMPDIR}, @env{TMP} or any other
  1091. location. For consistency we assume @env{TMPDIR} points to @file{/tmp}
  1092. for the remainder of this section.
  1093. @end quotation
  1094. @example
  1095. cd \$TMPDIR
  1096. wget https://ftp.gnu.org/gnu/gnunet/gnurl-7.65.3.tar.Z
  1097. wget https://ftp.gnu.org/gnu/gnunet/gnurl-7.65.3.tar.Z.sig
  1098. @end example
  1099. Next, verify the digital signature of the file:
  1100. @example
  1101. gpg --verify gnurl-7.65.3.tar.Z.sig
  1102. @end example
  1103. If gpg fails, you might try with @command{gpg2} on your OS. If the error
  1104. states that ``the key can not be found'' or it is unknown, you have to
  1105. retrieve the key (A88C8ADD129828D7EAC02E52E22F9BBFEE348588) from a
  1106. keyserver first:
  1107. @example
  1108. gpg --keyserver pgp.mit.edu --recv-keys A88C8ADD129828D7EAC02E52E22F9BBFEE348588
  1109. @end example
  1110. or
  1111. @example
  1112. gpg --keyserver hkps://keys.openpgp.org --recv-keys A88C8ADD129828D7EAC02E52E22F9BBFEE348588
  1113. @end example
  1114. and rerun the verification command.
  1115. libgnurl will require the following packages to be present at runtime:
  1116. GnuTLS (with DANE support / libunbound), libidn, zlib and at compile time:
  1117. libtool, perl, pkg-config, and (for tests) python (2.7, or
  1118. any version of python 3).
  1119. Once you have verified that all the required packages are present on your
  1120. system, we can proceed to compile libgnurl. This assumes you will install
  1121. gnurl in the default location as prefix. To change this, pass --prefix= to
  1122. the configure-gnurl script (which is a simple wrapper around configure).
  1123. @example
  1124. tar -xvf gnurl-7.65.3.tar.Z
  1125. cd gnurl-7.65.3
  1126. sh ./configure-gnurl
  1127. make
  1128. make -C tests test
  1129. sudo make install
  1130. @end example
  1131. After you've compiled and installed libgnurl, we can proceed to building
  1132. GNUnet.
  1133. First, in addition to the GNUnet sources you might require downloading the
  1134. latest version of various dependencies, depending on how recent the
  1135. software versions in your distribution of GNU/Linux are.
  1136. Most distributions do not include sufficiently recent versions of these
  1137. dependencies.
  1138. Thus, a typically installation on a "modern" GNU/Linux distribution
  1139. requires you to install the following dependencies (ideally in this
  1140. order):
  1141. @itemize @bullet
  1142. @item libgpgerror and libgcrypt
  1143. @item libnettle and libunbound (possibly from distribution), GnuTLS
  1144. @item libgnurl (read the README)
  1145. @item GNU libmicrohttpd
  1146. @item GNU libextractor
  1147. @end itemize
  1148. Make sure to first install the various mandatory and optional
  1149. dependencies including development headers from your distribution.
  1150. Other dependencies that you should strongly consider to install is a
  1151. database (MySQL, SQLite3 or Postgres).
  1152. The following instructions will assume that you installed at least
  1153. SQLite3 (commonly distributed as ``sqlite'' or ``sqlite3'').
  1154. For most distributions you should be able to find pre-build packages for
  1155. the database. Again, make sure to install the client libraries @b{and} the
  1156. respective development headers (if they are packaged separately) as well.
  1157. @c TODO: Do these platform specific descriptions still exist? If not,
  1158. @c we should find a way to sync website parts with this texinfo.
  1159. You can find specific, detailed instructions for installing of the
  1160. dependencies (and possibly the rest of the GNUnet installation) in the
  1161. platform-specific descriptions, which can be found in the Index.
  1162. Please consult them now.
  1163. If your distribution is not listed, please study the build
  1164. instructions for Debian stable, carefully as you try to install the
  1165. dependencies for your own distribution.
  1166. Contributing additional instructions for further platforms is always
  1167. appreciated.
  1168. Please take in mind that operating system development tends to move at
  1169. a rather fast speed. Due to this you should be aware that some of
  1170. the instructions could be outdated by the time you are reading this.
  1171. If you find a mistake, please tell us about it (or even better: send
  1172. a patch to the documentation to fix it!).
  1173. Before proceeding further, please double-check the dependency list.
  1174. Note that in addition to satisfying the dependencies, you might have to
  1175. make sure that development headers for the various libraries are also
  1176. installed.
  1177. There maybe files for other distributions, or you might be able to find
  1178. equivalent packages for your distribution.
  1179. While it is possible to build and install GNUnet without having root
  1180. access, we will assume that you have full control over your system in
  1181. these instructions.
  1182. First, you should create a system user @emph{gnunet} and an additional
  1183. group @emph{gnunetdns}. On the GNU/Linux distributions Debian and Ubuntu,
  1184. type:
  1185. @example
  1186. sudo adduser --system --home /var/lib/gnunet --group \
  1187. --disabled-password gnunet
  1188. sudo addgroup --system gnunetdns
  1189. @end example
  1190. @noindent
  1191. On other Unix-like systems, this should have the same effect:
  1192. @example
  1193. sudo useradd --system --groups gnunet --home-dir /var/lib/gnunet
  1194. sudo addgroup --system gnunetdns
  1195. @end example
  1196. Now compile and install GNUnet using:
  1197. @example
  1198. tar xvf gnunet-@value{VERSION}.tar.gz
  1199. cd gnunet-@value{VERSION}
  1200. ./configure --with-sudo=sudo --with-nssdir=/lib
  1201. make
  1202. sudo make install
  1203. @end example
  1204. If you want to be able to enable DEBUG-level log messages, add
  1205. @code{--enable-logging=verbose} to the end of the
  1206. @command{./configure} command.
  1207. @code{DEBUG}-level log messages are in English only and
  1208. should only be useful for developers (or for filing
  1209. really detailed bug reports).
  1210. @noindent
  1211. Next, edit the file @file{/etc/gnunet.conf} to contain the following:
  1212. @example
  1213. [arm]
  1214. START_SYSTEM_SERVICES = YES
  1215. START_USER_SERVICES = NO
  1216. @end example
  1217. @noindent
  1218. You may need to update your @code{ld.so} cache to include
  1219. files installed in @file{/usr/local/lib}:
  1220. @example
  1221. # ldconfig
  1222. @end example
  1223. @noindent
  1224. Then, switch from user @code{root} to user @code{gnunet} to start
  1225. the peer:
  1226. @example
  1227. # su -s /bin/sh - gnunet
  1228. $ gnunet-arm -c /etc/gnunet.conf -s
  1229. @end example
  1230. You may also want to add the last line in the gnunet user's @file{crontab}
  1231. prefixed with @code{@@reboot} so that it is executed whenever the system
  1232. is booted:
  1233. @example
  1234. @@reboot /usr/local/bin/gnunet-arm -c /etc/gnunet.conf -s
  1235. @end example
  1236. @noindent
  1237. This will only start the system-wide GNUnet services.
  1238. Type @command{exit} to get back your root shell.
  1239. Now, you need to configure the per-user part. For each
  1240. user that should get access to GNUnet on the system, run
  1241. (replace alice with your username):
  1242. @example
  1243. sudo adduser alice gnunet
  1244. @end example
  1245. @noindent
  1246. to allow them to access the system-wide GNUnet services. Then, each
  1247. user should create a configuration file @file{~/.config/gnunet.conf}
  1248. with the lines:
  1249. @example
  1250. [arm]
  1251. START_SYSTEM_SERVICES = NO
  1252. START_USER_SERVICES = YES
  1253. DEFAULTSERVICES = gns
  1254. @end example
  1255. @noindent
  1256. and start the per-user services using
  1257. @example
  1258. $ gnunet-arm -c ~/.config/gnunet.conf -s
  1259. @end example
  1260. @noindent
  1261. Again, adding a @code{crontab} entry to autostart the peer is advised:
  1262. @example
  1263. @@reboot /usr/local/bin/gnunet-arm -c $HOME/.config/gnunet.conf -s
  1264. @end example
  1265. @noindent
  1266. Note that some GNUnet services (such as socks5 proxies) may need a
  1267. system-wide TCP port for each user.
  1268. For those services, systems with more than one user may require each user
  1269. to specify a different port number in their personal configuration file.
  1270. Finally, the user should perform the basic initial setup for the GNU Name
  1271. System (GNS) certificate authority. This is done by running:
  1272. @example
  1273. $ gnunet-gns-proxy-setup-ca
  1274. @end example
  1275. @noindent
  1276. The first generates the default zones, whereas the second setups the GNS
  1277. Certificate Authority with the user's browser. Now, to activate GNS in the
  1278. normal DNS resolution process, you need to edit your
  1279. @file{/etc/nsswitch.conf} where you should find a line like this:
  1280. @example
  1281. hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
  1282. @end example
  1283. @noindent
  1284. The exact details may differ a bit, which is fine. Add the text
  1285. @emph{"gns [NOTFOUND=return]"} after @emph{"files"}.
  1286. Keep in mind that we included a backslash ("\") here just for
  1287. markup reasons. You should write the text below on @b{one line}
  1288. and @b{without} the "\":
  1289. @example
  1290. hosts: files gns [NOTFOUND=return] mdns4_minimal \
  1291. [NOTFOUND=return] dns mdns4
  1292. @end example
  1293. @c FIXME: Document new behavior.
  1294. You might want to make sure that @file{/lib/libnss_gns.so.2} exists on
  1295. your system, it should have been created during the installation.
  1296. @c **********************************************************************
  1297. @cindex TESTING library
  1298. @node TESTING library
  1299. @section TESTING library
  1300. The TESTING library is used for writing testcases which involve starting a
  1301. single or multiple peers. While peers can also be started by testcases
  1302. using the ARM subsystem, using TESTING library provides an elegant way to
  1303. do this. The configurations of the peers are auto-generated from a given
  1304. template to have non-conflicting port numbers ensuring that peers'
  1305. services do not run into bind errors. This is achieved by testing ports'
  1306. availability by binding a listening socket to them before allocating them
  1307. to services in the generated configurations.
  1308. An another advantage while using TESTING is that it shortens the testcase
  1309. startup time as the hostkeys for peers are copied from a pre-computed set
  1310. of hostkeys instead of generating them at peer startup which may take a
  1311. considerable amount of time when starting multiple peers or on an embedded
  1312. processor.
  1313. TESTING also allows for certain services to be shared among peers. This
  1314. feature is invaluable when testing with multiple peers as it helps to
  1315. reduce the number of services run per each peer and hence the total
  1316. number of processes run per testcase.
  1317. TESTING library only handles creating, starting and stopping peers.
  1318. Features useful for testcases such as connecting peers in a topology are
  1319. not available in TESTING but are available in the TESTBED subsystem.
  1320. Furthermore, TESTING only creates peers on the localhost, however by
  1321. using TESTBED testcases can benefit from creating peers across multiple
  1322. hosts.
  1323. @menu
  1324. * API::
  1325. * Finer control over peer stop::
  1326. * Helper functions::
  1327. * Testing with multiple processes::
  1328. @end menu
  1329. @cindex TESTING API
  1330. @node API
  1331. @subsection API
  1332. TESTING abstracts a group of peers as a TESTING system. All peers in a
  1333. system have common hostname and no two services of these peers have a
  1334. same port or a UNIX domain socket path.
  1335. TESTING system can be created with the function
  1336. @code{GNUNET_TESTING_system_create()} which returns a handle to the
  1337. system. This function takes a directory path which is used for generating
  1338. the configurations of peers, an IP address from which connections to the
  1339. peers' services should be allowed, the hostname to be used in peers'
  1340. configuration, and an array of shared service specifications of type
  1341. @code{struct GNUNET_TESTING_SharedService}.
  1342. The shared service specification must specify the name of the service to
  1343. share, the configuration pertaining to that shared service and the
  1344. maximum number of peers that are allowed to share a single instance of
  1345. the shared service.
  1346. TESTING system created with @code{GNUNET_TESTING_system_create()} chooses
  1347. ports from the default range @code{12000} - @code{56000} while
  1348. auto-generating configurations for peers.
  1349. This range can be customised with the function
  1350. @code{GNUNET_TESTING_system_create_with_portrange()}. This function is
  1351. similar to @code{GNUNET_TESTING_system_create()} except that it take 2
  1352. additional parameters --- the start and end of the port range to use.
  1353. A TESTING system is destroyed with the function
  1354. @code{GNUNET_TESTING_system_destory()}. This function takes the handle of
  1355. the system and a flag to remove the files created in the directory used
  1356. to generate configurations.
  1357. A peer is created with the function
  1358. @code{GNUNET_TESTING_peer_configure()}. This functions takes the system
  1359. handle, a configuration template from which the configuration for the peer
  1360. is auto-generated and the index from where the hostkey for the peer has to
  1361. be copied from. When successful, this function returns a handle to the
  1362. peer which can be used to start and stop it and to obtain the identity of
  1363. the peer. If unsuccessful, a NULL pointer is returned with an error
  1364. message. This function handles the generated configuration to have
  1365. non-conflicting ports and paths.
  1366. Peers can be started and stopped by calling the functions
  1367. @code{GNUNET_TESTING_peer_start()} and @code{GNUNET_TESTING_peer_stop()}
  1368. respectively. A peer can be destroyed by calling the function
  1369. @code{GNUNET_TESTING_peer_destroy}. When a peer is destroyed, the ports
  1370. and paths in allocated in its configuration are reclaimed for usage in new
  1371. peers.
  1372. @c ***********************************************************************
  1373. @node Finer control over peer stop
  1374. @subsection Finer control over peer stop
  1375. Using @code{GNUNET_TESTING_peer_stop()} is normally fine for testcases.
  1376. However, calling this function for each peer is inefficient when trying to
  1377. shutdown multiple peers as this function sends the termination signal to
  1378. the given peer process and waits for it to terminate. It would be faster
  1379. in this case to send the termination signals to the peers first and then
  1380. wait on them. This is accomplished by the functions
  1381. @code{GNUNET_TESTING_peer_kill()} which sends a termination signal to the
  1382. peer, and the function @code{GNUNET_TESTING_peer_wait()} which waits on
  1383. the peer.
  1384. Further finer control can be achieved by choosing to stop a peer
  1385. asynchronously with the function @code{GNUNET_TESTING_peer_stop_async()}.
  1386. This function takes a callback parameter and a closure for it in addition
  1387. to the handle to the peer to stop. The callback function is called with
  1388. the given closure when the peer is stopped. Using this function
  1389. eliminates blocking while waiting for the peer to terminate.
  1390. An asynchronous peer stop can be canceled by calling the function
  1391. @code{GNUNET_TESTING_peer_stop_async_cancel()}. Note that calling this
  1392. function does not prevent the peer from terminating if the termination
  1393. signal has already been sent to it. It does, however, cancels the
  1394. callback to be called when the peer is stopped.
  1395. @c ***********************************************************************
  1396. @node Helper functions
  1397. @subsection Helper functions
  1398. Most of the testcases can benefit from an abstraction which configures a
  1399. peer and starts it. This is provided by the function
  1400. @code{GNUNET_TESTING_peer_run()}. This function takes the testing
  1401. directory pathname, a configuration template, a callback and its closure.
  1402. This function creates a peer in the given testing directory by using the
  1403. configuration template, starts the peer and calls the given callback with
  1404. the given closure.
  1405. The function @code{GNUNET_TESTING_peer_run()} starts the ARM service of
  1406. the peer which starts the rest of the configured services. A similar
  1407. function @code{GNUNET_TESTING_service_run} can be used to just start a
  1408. single service of a peer. In this case, the peer's ARM service is not
  1409. started; instead, only the given service is run.
  1410. @c ***********************************************************************
  1411. @node Testing with multiple processes
  1412. @subsection Testing with multiple processes
  1413. When testing GNUnet, the splitting of the code into a services and clients
  1414. often complicates testing. The solution to this is to have the testcase
  1415. fork @code{gnunet-service-arm}, ask it to start the required server and
  1416. daemon processes and then execute appropriate client actions (to test the
  1417. client APIs or the core module or both). If necessary, multiple ARM
  1418. services can be forked using different ports (!) to simulate a network.
  1419. However, most of the time only one ARM process is needed. Note that on
  1420. exit, the testcase should shutdown ARM with a @code{TERM} signal (to give
  1421. it the chance to cleanly stop its child processes).
  1422. @c TODO: Is this still compiling and working as intended?
  1423. The following code illustrates spawning and killing an ARM process from a
  1424. testcase:
  1425. @example
  1426. static void run (void *cls,
  1427. char *const *args,
  1428. const char *cfgfile,
  1429. const struct GNUNET_CONFIGURATION_Handle *cfg) @{
  1430. struct GNUNET_OS_Process *arm_pid;
  1431. arm_pid = GNUNET_OS_start_process (NULL,
  1432. NULL,
  1433. "gnunet-service-arm",
  1434. "gnunet-service-arm",
  1435. "-c",
  1436. cfgname,
  1437. NULL);
  1438. /* do real test work here */
  1439. if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
  1440. GNUNET_log_strerror
  1441. (GNUNET_ERROR_TYPE_WARNING, "kill");
  1442. GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
  1443. GNUNET_OS_process_close (arm_pid); @}
  1444. GNUNET_PROGRAM_run (argc, argv,
  1445. "NAME-OF-TEST",
  1446. "nohelp",
  1447. options,
  1448. &run,
  1449. cls);
  1450. @end example
  1451. An alternative way that works well to test plugins is to implement a
  1452. mock-version of the environment that the plugin expects and then to
  1453. simply load the plugin directly.
  1454. @c ***********************************************************************
  1455. @node Performance regression analysis with Gauger
  1456. @section Performance regression analysis with Gauger
  1457. To help avoid performance regressions, GNUnet uses Gauger. Gauger is a
  1458. simple logging tool that allows remote hosts to send performance data to
  1459. a central server, where this data can be analyzed and visualized. Gauger
  1460. shows graphs of the repository revisions and the performance data recorded
  1461. for each revision, so sudden performance peaks or drops can be identified
  1462. and linked to a specific revision number.
  1463. In the case of GNUnet, the buildbots log the performance data obtained
  1464. during the tests after each build. The data can be accessed on GNUnet's
  1465. Gauger page.
  1466. The menu on the left allows to select either the results of just one
  1467. build bot (under "Hosts") or review the data from all hosts for a given
  1468. test result (under "Metrics"). In case of very different absolute value
  1469. of the results, for instance arm vs. amd64 machines, the option
  1470. "Normalize" on a metric view can help to get an idea about the
  1471. performance evolution across all hosts.
  1472. Using Gauger in GNUnet and having the performance of a module tracked over
  1473. time is very easy. First of course, the testcase must generate some
  1474. consistent metric, which makes sense to have logged. Highly volatile or
  1475. random dependent metrics probably are not ideal candidates for meaningful
  1476. regression detection.
  1477. To start logging any value, just include @code{gauger.h} in your testcase
  1478. code. Then, use the macro @code{GAUGER()} to make the Buildbots log
  1479. whatever value is of interest for you to @code{gnunet.org}'s Gauger
  1480. server. No setup is necessary as most Buildbots have already everything
  1481. in place and new metrics are created on demand. To delete a metric, you
  1482. need to contact a member of the GNUnet development team (a file will need
  1483. to be removed manually from the respective directory).
  1484. The code in the test should look like this:
  1485. @example
  1486. [other includes]
  1487. #include <gauger.h>
  1488. int main (int argc, char *argv[]) @{
  1489. [run test, generate data]
  1490. GAUGER("YOUR_MODULE",
  1491. "METRIC_NAME",
  1492. (float)value,
  1493. "UNIT"); @}
  1494. @end example
  1495. Where:
  1496. @table @asis
  1497. @item @strong{YOUR_MODULE} is a category in the gauger page and should be
  1498. the name of the module or subsystem like "Core" or "DHT"
  1499. @item @strong{METRIC} is
  1500. the name of the metric being collected and should be concise and
  1501. descriptive, like "PUT operations in sqlite-datastore".
  1502. @item @strong{value} is the value
  1503. of the metric that is logged for this run.
  1504. @item @strong{UNIT} is the unit in
  1505. which the value is measured, for instance "kb/s" or "kb of RAM/node".
  1506. @end table
  1507. If you wish to use Gauger for your own project, you can grab a copy of the
  1508. latest stable release or check out Gauger's Subversion repository.
  1509. @cindex TESTBED Subsystem
  1510. @node TESTBED Subsystem
  1511. @section TESTBED Subsystem
  1512. The TESTBED subsystem facilitates testing and measuring of multi-peer
  1513. deployments on a single host or over multiple hosts.
  1514. The architecture of the testbed module is divided into the following:
  1515. @itemize @bullet
  1516. @item Testbed API: An API which is used by the testing driver programs. It
  1517. provides with functions for creating, destroying, starting, stopping
  1518. peers, etc.
  1519. @item Testbed service (controller): A service which is started through the
  1520. Testbed API. This service handles operations to create, destroy, start,
  1521. stop peers, connect them, modify their configurations.
  1522. @item Testbed helper: When a controller has to be started on a host, the
  1523. testbed API starts the testbed helper on that host which in turn starts
  1524. the controller. The testbed helper receives a configuration for the
  1525. controller through its stdin and changes it to ensure the controller
  1526. doesn't run into any port conflict on that host.
  1527. @end itemize
  1528. The testbed service (controller) is different from the other GNUnet
  1529. services in that it is not started by ARM and is not supposed to be run
  1530. as a daemon. It is started by the testbed API through a testbed helper.
  1531. In a typical scenario involving multiple hosts, a controller is started
  1532. on each host. Controllers take up the actual task of creating peers,
  1533. starting and stopping them on the hosts they run.
  1534. While running deployments on a single localhost the testbed API starts the
  1535. testbed helper directly as a child process. When running deployments on
  1536. remote hosts the testbed API starts Testbed Helpers on each remote host
  1537. through remote shell. By default testbed API uses SSH as a remote shell.
  1538. This can be changed by setting the environmental variable
  1539. GNUNET_TESTBED_RSH_CMD to the required remote shell program. This
  1540. variable can also contain parameters which are to be passed to the remote
  1541. shell program. For e.g:
  1542. @example
  1543. export GNUNET_TESTBED_RSH_CMD="ssh -o BatchMode=yes \
  1544. -o NoHostAuthenticationForLocalhost=yes %h"
  1545. @end example
  1546. Substitutions are allowed in the command string above,
  1547. this allows for substitutions through placemarks which begin with a `%'.
  1548. At present the following substitutions are supported
  1549. @itemize @bullet
  1550. @item %h: hostname
  1551. @item %u: username
  1552. @item %p: port
  1553. @end itemize
  1554. Note that the substitution placemark is replaced only when the
  1555. corresponding field is available and only once. Specifying
  1556. @example
  1557. %u@@%h
  1558. @end example
  1559. doesn't work either. If you want to user username substitutions for
  1560. @command{SSH}, use the argument @code{-l} before the
  1561. username substitution.
  1562. For example:
  1563. @example
  1564. ssh -l %u -p %p %h
  1565. @end example
  1566. The testbed API and the helper communicate through the helpers stdin and
  1567. stdout. As the helper is started through a remote shell on remote hosts
  1568. any output messages from the remote shell interfere with the communication
  1569. and results in a failure while starting the helper. For this reason, it is
  1570. suggested to use flags to make the remote shells produce no output
  1571. messages and to have password-less logins. The default remote shell, SSH,
  1572. the default options are:
  1573. @example
  1574. -o BatchMode=yes -o NoHostBasedAuthenticationForLocalhost=yes"
  1575. @end example
  1576. Password-less logins should be ensured by using SSH keys.
  1577. Since the testbed API executes the remote shell as a non-interactive
  1578. shell, certain scripts like .bashrc, .profiler may not be executed. If
  1579. this is the case testbed API can be forced to execute an interactive
  1580. shell by setting up the environmental variable
  1581. @code{GNUNET_TESTBED_RSH_CMD_SUFFIX} to a shell program.
  1582. An example could be:
  1583. @example
  1584. export GNUNET_TESTBED_RSH_CMD_SUFFIX="sh -lc"
  1585. @end example
  1586. The testbed API will then execute the remote shell program as:
  1587. @example
  1588. $GNUNET_TESTBED_RSH_CMD -p $port $dest $GNUNET_TESTBED_RSH_CMD_SUFFIX \
  1589. gnunet-helper-testbed
  1590. @end example
  1591. On some systems, problems may arise while starting testbed helpers if
  1592. GNUnet is installed into a custom location since the helper may not be
  1593. found in the standard path. This can be addressed by setting the variable
  1594. `@code{HELPER_BINARY_PATH}' to the path of the testbed helper.
  1595. Testbed API will then use this path to start helper binaries both
  1596. locally and remotely.
  1597. Testbed API can accessed by including the
  1598. @file{gnunet_testbed_service.h} file and linking with
  1599. @code{-lgnunettestbed}.
  1600. @c ***********************************************************************
  1601. @menu
  1602. * Supported Topologies::
  1603. * Hosts file format::
  1604. * Topology file format::
  1605. * Testbed Barriers::
  1606. * TESTBED Caveats::
  1607. @end menu
  1608. @node Supported Topologies
  1609. @subsection Supported Topologies
  1610. While testing multi-peer deployments, it is often needed that the peers
  1611. are connected in some topology. This requirement is addressed by the
  1612. function @code{GNUNET_TESTBED_overlay_connect()} which connects any given
  1613. two peers in the testbed.
  1614. The API also provides a helper function
  1615. @code{GNUNET_TESTBED_overlay_configure_topology()} to connect a given set
  1616. of peers in any of the following supported topologies:
  1617. @itemize @bullet
  1618. @item @code{GNUNET_TESTBED_TOPOLOGY_CLIQUE}: All peers are connected with
  1619. each other
  1620. @item @code{GNUNET_TESTBED_TOPOLOGY_LINE}: Peers are connected to form a
  1621. line
  1622. @item @code{GNUNET_TESTBED_TOPOLOGY_RING}: Peers are connected to form a
  1623. ring topology
  1624. @item @code{GNUNET_TESTBED_TOPOLOGY_2D_TORUS}: Peers are connected to
  1625. form a 2 dimensional torus topology. The number of peers may not be a
  1626. perfect square, in that case the resulting torus may not have the uniform
  1627. poloidal and toroidal lengths
  1628. @item @code{GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI}: Topology is generated
  1629. to form a random graph. The number of links to be present should be given
  1630. @item @code{GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD}: Peers are connected to
  1631. form a 2D Torus with some random links among them. The number of random
  1632. links are to be given
  1633. @item @code{GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING}: Peers are
  1634. connected to form a ring with some random links among them. The number of
  1635. random links are to be given
  1636. @item @code{GNUNET_TESTBED_TOPOLOGY_SCALE_FREE}: Connects peers in a
  1637. topology where peer connectivity follows power law - new peers are
  1638. connected with high probability to well connected peers.
  1639. (See Emergence of Scaling in Random Networks. Science 286,
  1640. 509-512, 1999
  1641. (@uref{https://git.gnunet.org/bibliography.git/plain/docs/emergence_of_scaling_in_random_networks__barabasi_albert_science_286__1999.pdf, pdf}))
  1642. @item @code{GNUNET_TESTBED_TOPOLOGY_FROM_FILE}: The topology information
  1643. is loaded from a file. The path to the file has to be given.
  1644. @xref{Topology file format}, for the format of this file.
  1645. @item @code{GNUNET_TESTBED_TOPOLOGY_NONE}: No topology
  1646. @end itemize
  1647. The above supported topologies can be specified respectively by setting
  1648. the variable @code{OVERLAY_TOPOLOGY} to the following values in the
  1649. configuration passed to Testbed API functions
  1650. @code{GNUNET_TESTBED_test_run()} and
  1651. @code{GNUNET_TESTBED_run()}:
  1652. @itemize @bullet
  1653. @item @code{CLIQUE}
  1654. @item @code{RING}
  1655. @item @code{LINE}
  1656. @item @code{2D_TORUS}
  1657. @item @code{RANDOM}
  1658. @item @code{SMALL_WORLD}
  1659. @item @code{SMALL_WORLD_RING}
  1660. @item @code{SCALE_FREE}
  1661. @item @code{FROM_FILE}
  1662. @item @code{NONE}
  1663. @end itemize
  1664. Topologies @code{RANDOM}, @code{SMALL_WORLD} and @code{SMALL_WORLD_RING}
  1665. require the option @code{OVERLAY_RANDOM_LINKS} to be set to the number of
  1666. random links to be generated in the configuration. The option will be
  1667. ignored for the rest of the topologies.
  1668. Topology @code{SCALE_FREE} requires the options
  1669. @code{SCALE_FREE_TOPOLOGY_CAP} to be set to the maximum number of peers
  1670. which can connect to a peer and @code{SCALE_FREE_TOPOLOGY_M} to be set to
  1671. how many peers a peer should be at least connected to.
  1672. Similarly, the topology @code{FROM_FILE} requires the option
  1673. @code{OVERLAY_TOPOLOGY_FILE} to contain the path of the file containing
  1674. the topology information. This option is ignored for the rest of the
  1675. topologies. @xref{Topology file format}, for the format of this file.
  1676. @c ***********************************************************************
  1677. @node Hosts file format
  1678. @subsection Hosts file format
  1679. The testbed API offers the function
  1680. @code{GNUNET_TESTBED_hosts_load_from_file()} to load from a given file
  1681. details about the hosts which testbed can use for deploying peers.
  1682. This function is useful to keep the data about hosts
  1683. separate instead of hard coding them in code.
  1684. Another helper function from testbed API, @code{GNUNET_TESTBED_run()}
  1685. also takes a hosts file name as its parameter. It uses the above
  1686. function to populate the hosts data structures and start controllers to
  1687. deploy peers.
  1688. These functions require the hosts file to be of the following format:
  1689. @itemize @bullet
  1690. @item Each line is interpreted to have details about a host
  1691. @item Host details should include the username to use for logging into the
  1692. host, the hostname of the host and the port number to use for the remote
  1693. shell program. All thee values should be given.
  1694. @item These details should be given in the following format:
  1695. @example
  1696. <username>@@<hostname>:<port>
  1697. @end example
  1698. @end itemize
  1699. Note that having canonical hostnames may cause problems while resolving
  1700. the IP addresses (See this bug). Hence it is advised to provide the hosts'
  1701. IP numerical addresses as hostnames whenever possible.
  1702. @c ***********************************************************************
  1703. @node Topology file format
  1704. @subsection Topology file format
  1705. A topology file describes how peers are to be connected. It should adhere
  1706. to the following format for testbed to parse it correctly.
  1707. Each line should begin with the target peer id. This should be followed by
  1708. a colon(`:') and origin peer ids separated by `|'. All spaces except for
  1709. newline characters are ignored. The API will then try to connect each
  1710. origin peer to the target peer.
  1711. For example, the following file will result in 5 overlay connections:
  1712. [2->1], [3->1],[4->3], [0->3], [2->0]@
  1713. @code{@ 1:2|3@ 3:4| 0@ 0: 2@ }
  1714. @c ***********************************************************************
  1715. @node Testbed Barriers
  1716. @subsection Testbed Barriers
  1717. The testbed subsystem's barriers API facilitates coordination among the
  1718. peers run by the testbed and the experiment driver. The concept is
  1719. similar to the barrier synchronisation mechanism found in parallel
  1720. programming or multi-threading paradigms - a peer waits at a barrier upon
  1721. reaching it until the barrier is reached by a predefined number of peers.
  1722. This predefined number of peers required to cross a barrier is also called
  1723. quorum. We say a peer has reached a barrier if the peer is waiting for the
  1724. barrier to be crossed. Similarly a barrier is said to be reached if the
  1725. required quorum of peers reach the barrier. A barrier which is reached is
  1726. deemed as crossed after all the peers waiting on it are notified.
  1727. The barriers API provides the following functions:
  1728. @itemize @bullet
  1729. @item @strong{@code{GNUNET_TESTBED_barrier_init()}:} function to
  1730. initialize a barrier in the experiment
  1731. @item @strong{@code{GNUNET_TESTBED_barrier_cancel()}:} function to cancel
  1732. a barrier which has been initialized before
  1733. @item @strong{@code{GNUNET_TESTBED_barrier_wait()}:} function to signal
  1734. barrier service that the caller has reached a barrier and is waiting for
  1735. it to be crossed
  1736. @item @strong{@code{GNUNET_TESTBED_barrier_wait_cancel()}:} function to
  1737. stop waiting for a barrier to be crossed
  1738. @end itemize
  1739. Among the above functions, the first two, namely
  1740. @code{GNUNET_TESTBED_barrier_init()} and
  1741. @code{GNUNET_TESTBED_barrier_cancel()} are used by experiment drivers. All
  1742. barriers should be initialised by the experiment driver by calling
  1743. @code{GNUNET_TESTBED_barrier_init()}. This function takes a name to
  1744. identify the barrier, the quorum required for the barrier to be crossed
  1745. and a notification callback for notifying the experiment driver when the
  1746. barrier is crossed. @code{GNUNET_TESTBED_barrier_cancel()} cancels an
  1747. initialised barrier and frees the resources allocated for it. This
  1748. function can be called upon a initialised barrier before it is crossed.
  1749. The remaining two functions @code{GNUNET_TESTBED_barrier_wait()} and
  1750. @code{GNUNET_TESTBED_barrier_wait_cancel()} are used in the peer's
  1751. processes. @code{GNUNET_TESTBED_barrier_wait()} connects to the local
  1752. barrier service running on the same host the peer is running on and
  1753. registers that the caller has reached the barrier and is waiting for the
  1754. barrier to be crossed. Note that this function can only be used by peers
  1755. which are started by testbed as this function tries to access the local
  1756. barrier service which is part of the testbed controller service. Calling
  1757. @code{GNUNET_TESTBED_barrier_wait()} on an uninitialised barrier results
  1758. in failure. @code{GNUNET_TESTBED_barrier_wait_cancel()} cancels the
  1759. notification registered by @code{GNUNET_TESTBED_barrier_wait()}.
  1760. @c ***********************************************************************
  1761. @menu
  1762. * Implementation::
  1763. @end menu
  1764. @node Implementation
  1765. @subsubsection Implementation
  1766. Since barriers involve coordination between experiment driver and peers,
  1767. the barrier service in the testbed controller is split into two
  1768. components. The first component responds to the message generated by the
  1769. barrier API used by the experiment driver (functions
  1770. @code{GNUNET_TESTBED_barrier_init()} and
  1771. @code{GNUNET_TESTBED_barrier_cancel()}) and the second component to the
  1772. messages generated by barrier API used by peers (functions
  1773. @code{GNUNET_TESTBED_barrier_wait()} and
  1774. @code{GNUNET_TESTBED_barrier_wait_cancel()}).
  1775. Calling @code{GNUNET_TESTBED_barrier_init()} sends a
  1776. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT} message to the master
  1777. controller. The master controller then registers a barrier and calls
  1778. @code{GNUNET_TESTBED_barrier_init()} for each its subcontrollers. In this
  1779. way barrier initialisation is propagated to the controller hierarchy.
  1780. While propagating initialisation, any errors at a subcontroller such as
  1781. timeout during further propagation are reported up the hierarchy back to
  1782. the experiment driver.
  1783. Similar to @code{GNUNET_TESTBED_barrier_init()},
  1784. @code{GNUNET_TESTBED_barrier_cancel()} propagates
  1785. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL} message which causes
  1786. controllers to remove an initialised barrier.
  1787. The second component is implemented as a separate service in the binary
  1788. `gnunet-service-testbed' which already has the testbed controller service.
  1789. Although this deviates from the gnunet process architecture of having one
  1790. service per binary, it is needed in this case as this component needs
  1791. access to barrier data created by the first component. This component
  1792. responds to @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT} messages from
  1793. local peers when they call @code{GNUNET_TESTBED_barrier_wait()}. Upon
  1794. receiving @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT} message, the
  1795. service checks if the requested barrier has been initialised before and
  1796. if it was not initialised, an error status is sent through
  1797. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS} message to the local
  1798. peer and the connection from the peer is terminated. If the barrier is
  1799. initialised before, the barrier's counter for reached peers is incremented
  1800. and a notification is registered to notify the peer when the barrier is
  1801. reached. The connection from the peer is left open.
  1802. When enough peers required to attain the quorum send
  1803. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT} messages, the controller
  1804. sends a @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS} message to its
  1805. parent informing that the barrier is crossed. If the controller has
  1806. started further subcontrollers, it delays this message until it receives
  1807. a similar notification from each of those subcontrollers. Finally, the
  1808. barriers API at the experiment driver receives the
  1809. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS} when the barrier is
  1810. reached at all the controllers.
  1811. The barriers API at the experiment driver responds to the
  1812. @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS} message by echoing it
  1813. back to the master controller and notifying the experiment controller
  1814. through the notification callback that a barrier has been crossed. The
  1815. echoed @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS} message is
  1816. propagated by the master controller to the controller hierarchy. This
  1817. propagation triggers the notifications registered by peers at each of the
  1818. controllers in the hierarchy. Note the difference between this downward
  1819. propagation of the @code{GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS}
  1820. message from its upward propagation --- the upward propagation is needed
  1821. for ensuring that the barrier is reached by all the controllers and the
  1822. downward propagation is for triggering that the barrier is crossed.
  1823. @cindex TESTBED Caveats
  1824. @node TESTBED Caveats
  1825. @subsection TESTBED Caveats
  1826. This section documents a few caveats when using the GNUnet testbed
  1827. subsystem.
  1828. @c ***********************************************************************
  1829. @menu
  1830. * CORE must be started::
  1831. * ATS must want the connections::
  1832. @end menu
  1833. @node CORE must be started
  1834. @subsubsection CORE must be started
  1835. A uncomplicated issue is bug #3993
  1836. (@uref{https://bugs.gnunet.org/view.php?id=3993, https://bugs.gnunet.org/view.php?id=3993}):
  1837. Your configuration MUST somehow ensure that for each peer the
  1838. @code{CORE} service is started when the peer is setup, otherwise
  1839. @code{TESTBED} may fail to connect peers when the topology is initialized,
  1840. as @code{TESTBED} will start some @code{CORE} services but not
  1841. necessarily all (but it relies on all of them running). The easiest way
  1842. is to set
  1843. @example
  1844. [core]
  1845. IMMEDIATE_START = YES
  1846. @end example
  1847. @noindent
  1848. in the configuration file.
  1849. Alternatively, having any service that directly or indirectly depends on
  1850. @code{CORE} being started with @code{IMMEDIATE_START} will also do.
  1851. This issue largely arises if users try to over-optimize by not
  1852. starting any services with @code{IMMEDIATE_START}.
  1853. @c ***********************************************************************
  1854. @node ATS must want the connections
  1855. @subsubsection ATS must want the connections
  1856. When TESTBED sets up connections, it only offers the respective HELLO
  1857. information to the TRANSPORT service. It is then up to the ATS service to
  1858. @strong{decide} to use the connection. The ATS service will typically
  1859. eagerly establish any connection if the number of total connections is
  1860. low (relative to bandwidth). Details may further depend on the
  1861. specific ATS backend that was configured. If ATS decides to NOT establish
  1862. a connection (even though TESTBED provided the required information), then
  1863. that connection will count as failed for TESTBED. Note that you can
  1864. configure TESTBED to tolerate a certain number of connection failures
  1865. (see '-e' option of gnunet-testbed-profiler). This issue largely arises
  1866. for dense overlay topologies, especially if you try to create cliques
  1867. with more than 20 peers.
  1868. @cindex libgnunetutil
  1869. @node libgnunetutil
  1870. @section libgnunetutil
  1871. libgnunetutil is the fundamental library that all GNUnet code builds upon.
  1872. Ideally, this library should contain most of the platform dependent code
  1873. (except for user interfaces and really special needs that only few
  1874. applications have). It is also supposed to offer basic services that most
  1875. if not all GNUnet binaries require. The code of libgnunetutil is in the
  1876. @file{src/util/} directory. The public interface to the library is in the
  1877. gnunet_util.h header. The functions provided by libgnunetutil fall
  1878. roughly into the following categories (in roughly the order of importance
  1879. for new developers):
  1880. @itemize @bullet
  1881. @item logging (common_logging.c)
  1882. @item memory allocation (common_allocation.c)
  1883. @item endianess conversion (common_endian.c)
  1884. @item internationalization (common_gettext.c)
  1885. @item String manipulation (string.c)
  1886. @item file access (disk.c)
  1887. @item buffered disk IO (bio.c)
  1888. @item time manipulation (time.c)
  1889. @item configuration parsing (configuration.c)
  1890. @item command-line handling (getopt*.c)
  1891. @item cryptography (crypto_*.c)
  1892. @item data structures (container_*.c)
  1893. @item CPS-style scheduling (scheduler.c)
  1894. @item Program initialization (program.c)
  1895. @item Networking (network.c, client.c, server*.c, service.c)
  1896. @item message queuing (mq.c)
  1897. @item bandwidth calculations (bandwidth.c)
  1898. @item Other OS-related (os*.c, plugin.c, signal.c)
  1899. @item Pseudonym management (pseudonym.c)
  1900. @end itemize
  1901. It should be noted that only developers that fully understand this entire
  1902. API will be able to write good GNUnet code.
  1903. Ideally, porting GNUnet should only require porting the gnunetutil
  1904. library. More testcases for the gnunetutil APIs are therefore a great
  1905. way to make porting of GNUnet easier.
  1906. @menu
  1907. * Logging::
  1908. * Interprocess communication API (IPC)::
  1909. * Cryptography API::
  1910. * Message Queue API::
  1911. * Service API::
  1912. * Optimizing Memory Consumption of GNUnet's (Multi-) Hash Maps::
  1913. * CONTAINER_MDLL API::
  1914. @end menu
  1915. @cindex Logging
  1916. @cindex log levels
  1917. @node Logging
  1918. @subsection Logging
  1919. GNUnet is able to log its activity, mostly for the purposes of debugging
  1920. the program at various levels.
  1921. @file{gnunet_common.h} defines several @strong{log levels}:
  1922. @table @asis
  1923. @item ERROR for errors
  1924. (really problematic situations, often leading to crashes)
  1925. @item WARNING for warnings
  1926. (troubling situations that might have negative consequences, although
  1927. not fatal)
  1928. @item INFO for various information.
  1929. Used somewhat rarely, as GNUnet statistics is used to hold and display
  1930. most of the information that users might find interesting.
  1931. @item DEBUG for debugging.
  1932. Does not produce much output on normal builds, but when extra logging is
  1933. enabled at compile time, a staggering amount of data is outputted under
  1934. this log level.
  1935. @end table
  1936. Normal builds of GNUnet (configured with @code{--enable-logging[=yes]})
  1937. are supposed to log nothing under DEBUG level. The
  1938. @code{--enable-logging=verbose} configure option can be used to create a
  1939. build with all logging enabled. However, such build will produce large
  1940. amounts of log data, which is inconvenient when one tries to hunt down a
  1941. specific problem.
  1942. To mitigate this problem, GNUnet provides facilities to apply a filter to
  1943. reduce the logs:
  1944. @table @asis
  1945. @item Logging by default When no log levels are configured in any other
  1946. way (see below), GNUnet will default to the WARNING log level. This
  1947. mostly applies to GNUnet command line utilities, services and daemons;
  1948. tests will always set log level to WARNING or, if
  1949. @code{--enable-logging=verbose} was passed to configure, to DEBUG. The
  1950. default level is suggested for normal operation.
  1951. @item The -L option Most GNUnet executables accept an "-L loglevel" or
  1952. "--log=loglevel" option. If used, it makes the process set a global log
  1953. level to "loglevel". Thus it is possible to run some processes
  1954. with -L DEBUG, for example, and others with -L ERROR to enable specific
  1955. settings to diagnose problems with a particular process.
  1956. @item Configuration files. Because GNUnet
  1957. service and daemon processes are usually launched by gnunet-arm, it is not
  1958. possible to pass different custom command line options directly to every
  1959. one of them. The options passed to @code{gnunet-arm} only affect
  1960. gnunet-arm and not the rest of GNUnet. However, one can specify a
  1961. configuration key "OPTIONS" in the section that corresponds to a service
  1962. or a daemon, and put a value of "-L loglevel" there. This will make the
  1963. respective service or daemon set its log level to "loglevel" (as the
  1964. value of OPTIONS will be passed as a command-line argument).
  1965. To specify the same log level for all services without creating separate
  1966. "OPTIONS" entries in the configuration for each one, the user can specify
  1967. a config key "GLOBAL_POSTFIX" in the [arm] section of the configuration
  1968. file. The value of GLOBAL_POSTFIX will be appended to all command lines
  1969. used by the ARM service to run other services. It can contain any option
  1970. valid for all GNUnet commands, thus in particular the "-L loglevel"
  1971. option. The ARM service itself is, however, unaffected by GLOBAL_POSTFIX;
  1972. to set log level for it, one has to specify "OPTIONS" key in the [arm]
  1973. section.
  1974. @item Environment variables.
  1975. Setting global per-process log levels with "-L loglevel" does not offer
  1976. sufficient log filtering granularity, as one service will call interface
  1977. libraries and supporting libraries of other GNUnet services, potentially
  1978. producing lots of debug log messages from these libraries. Also, changing
  1979. the config file is not always convenient (especially when running the
  1980. GNUnet test suite).@ To fix that, and to allow GNUnet to use different
  1981. log filtering at runtime without re-compiling the whole source tree, the
  1982. log calls were changed to be configurable at run time. To configure them
  1983. one has to define environment variables "GNUNET_FORCE_LOGFILE",
  1984. "GNUNET_LOG" and/or "GNUNET_FORCE_LOG":
  1985. @itemize @bullet
  1986. @item "GNUNET_LOG" only affects the logging when no global log level is
  1987. configured by any other means (that is, the process does not explicitly
  1988. set its own log level, there are no "-L loglevel" options on command line
  1989. or in configuration files), and can be used to override the default
  1990. WARNING log level.
  1991. @item "GNUNET_FORCE_LOG" will completely override any other log
  1992. configuration options given.
  1993. @item "GNUNET_FORCE_LOGFILE" will completely override the location of the
  1994. file to log messages to. It should contain a relative or absolute file
  1995. name. Setting GNUNET_FORCE_LOGFILE is equivalent to passing
  1996. "--log-file=logfile" or "-l logfile" option (see below). It supports "[]"
  1997. format in file names, but not "@{@}" (see below).
  1998. @end itemize
  1999. Because environment variables are inherited by child processes when they
  2000. are launched, starting or re-starting the ARM service with these
  2001. variables will propagate them to all other services.
  2002. "GNUNET_LOG" and "GNUNET_FORCE_LOG" variables must contain a specially
  2003. formatted @strong{logging definition} string, which looks like this:@
  2004. @c FIXME: Can we close this with [/component] instead?
  2005. @example
  2006. [component];[file];[function];[from_line[-to_line]];loglevel[/component...]
  2007. @end example
  2008. That is, a logging definition consists of definition entries, separated by
  2009. slashes ('/'). If only one entry is present, there is no need to add a
  2010. slash to its end (although it is not forbidden either).@ All definition
  2011. fields (component, file, function, lines and loglevel) are mandatory, but
  2012. (except for the loglevel) they can be empty. An empty field means
  2013. "match anything". Note that even if fields are empty, the semicolon (';')
  2014. separators must be present.@ The loglevel field is mandatory, and must
  2015. contain one of the log level names (ERROR, WARNING, INFO or DEBUG).@
  2016. The lines field might contain one non-negative number, in which case it
  2017. matches only one line, or a range "from_line-to_line", in which case it
  2018. matches any line in the interval [from_line;to_line] (that is, including
  2019. both start and end line).@ GNUnet mostly defaults component name to the
  2020. name of the service that is implemented in a process ('transport',
  2021. 'core', 'peerinfo', etc), but logging calls can specify custom component
  2022. names using @code{GNUNET_log_from}.@ File name and function name are
  2023. provided by the compiler (__FILE__ and __FUNCTION__ built-ins).
  2024. Component, file and function fields are interpreted as non-extended
  2025. regular expressions (GNU libc regex functions are used). Matching is
  2026. case-sensitive, "^" and "$" will match the beginning and the end of the
  2027. text. If a field is empty, its contents are automatically replaced with
  2028. a ".*" regular expression, which matches anything. Matching is done in
  2029. the default way, which means that the expression matches as long as it's
  2030. contained anywhere in the string. Thus "GNUNET_" will match both
  2031. "GNUNET_foo" and "BAR_GNUNET_BAZ". Use '^' and/or '$' to make sure that
  2032. the expression matches at the start and/or at the end of the string.
  2033. The semicolon (';') can't be escaped, and GNUnet will not use it in
  2034. component names (it can't be used in function names and file names
  2035. anyway).
  2036. @end table
  2037. Every logging call in GNUnet code will be (at run time) matched against
  2038. the log definitions passed to the process. If a log definition fields are
  2039. matching the call arguments, then the call log level is compared to the
  2040. log level of that definition. If the call log level is less or equal to
  2041. the definition log level, the call is allowed to proceed. Otherwise the
  2042. logging call is forbidden, and nothing is logged. If no definitions
  2043. matched at all, GNUnet will use the global log level or (if a global log
  2044. level is not specified) will default to WARNING (that is, it will allow
  2045. the call to proceed, if its level is less or equal to the global log
  2046. level or to WARNING).
  2047. That is, definitions are evaluated from left to right, and the first
  2048. matching definition is used to allow or deny the logging call. Thus it is
  2049. advised to place narrow definitions at the beginning of the logdef
  2050. string, and generic definitions - at the end.
  2051. Whether a call is allowed or not is only decided the first time this
  2052. particular call is made. The evaluation result is then cached, so that
  2053. any attempts to make the same call later will be allowed or disallowed
  2054. right away. Because of that runtime log level evaluation should not
  2055. significantly affect the process performance.
  2056. Log definition parsing is only done once, at the first call to
  2057. @code{GNUNET_log_setup ()} made by the process (which is usually
  2058. done soon after it starts).
  2059. At the moment of writing there is no way to specify logging definitions
  2060. from configuration files, only via environment variables.
  2061. At the moment GNUnet will stop processing a log definition when it
  2062. encounters an error in definition formatting or an error in regular
  2063. expression syntax, and will not report the failure in any way.
  2064. @c ***********************************************************************
  2065. @menu
  2066. * Examples::
  2067. * Log files::
  2068. * Updated behavior of GNUNET_log::
  2069. @end menu
  2070. @node Examples
  2071. @subsubsection Examples
  2072. @table @asis
  2073. @item @code{GNUNET_FORCE_LOG=";;;;DEBUG" gnunet-arm -s} Start GNUnet
  2074. process tree, running all processes with DEBUG level (one should be
  2075. careful with it, as log files will grow at alarming rate!)
  2076. @item @code{GNUNET_FORCE_LOG="core;;;;DEBUG" gnunet-arm -s} Start GNUnet
  2077. process tree, running the core service under DEBUG level (everything else
  2078. will use configured or default level).
  2079. @item Start GNUnet process tree, allowing any logging calls from
  2080. gnunet-service-transport_validation.c (everything else will use
  2081. configured or default level).
  2082. @example
  2083. GNUNET_FORCE_LOG=";gnunet-service-transport_validation.c;;; DEBUG" \
  2084. gnunet-arm -s
  2085. @end example
  2086. @item Start GNUnet process tree, allowing any logging calls from
  2087. gnunet-gnunet-service-fs_push.c (everything else will use configured or
  2088. default level).
  2089. @example
  2090. GNUNET_FORCE_LOG="fs;gnunet-service-fs_push.c;;;DEBUG" gnunet-arm -s
  2091. @end example
  2092. @item Start GNUnet process tree, allowing any logging calls from the
  2093. GNUNET_NETWORK_socket_select function (everything else will use
  2094. configured or default level).
  2095. @example
  2096. GNUNET_FORCE_LOG=";;GNUNET_NETWORK_socket_select;;DEBUG" gnunet-arm -s
  2097. @end example
  2098. @item Start GNUnet process tree, allowing any logging calls from the
  2099. components that have "transport" in their names, and are made from
  2100. function that have "send" in their names. Everything else will be allowed
  2101. to be logged only if it has WARNING level.
  2102. @example
  2103. GNUNET_FORCE_LOG="transport.*;;.*send.*;;DEBUG/;;;;WARNING" gnunet-arm -s
  2104. @end example
  2105. @end table
  2106. On Windows, one can use batch files to run GNUnet processes with special
  2107. environment variables, without affecting the whole system. Such batch
  2108. file will look like this:
  2109. @example
  2110. set GNUNET_FORCE_LOG=;;do_transmit;;DEBUG@ gnunet-arm -s
  2111. @end example
  2112. (note the absence of double quotes in the environment variable definition,
  2113. as opposed to earlier examples, which use the shell).
  2114. Another limitation, on Windows, GNUNET_FORCE_LOGFILE @strong{MUST} be set
  2115. in order to GNUNET_FORCE_LOG to work.
  2116. @cindex Log files
  2117. @node Log files
  2118. @subsubsection Log files
  2119. GNUnet can be told to log everything into a file instead of stderr (which
  2120. is the default) using the "--log-file=logfile" or "-l logfile" option.
  2121. This option can also be passed via command line, or from the "OPTION" and
  2122. "GLOBAL_POSTFIX" configuration keys (see above). The file name passed
  2123. with this option is subject to GNUnet filename expansion. If specified in
  2124. "GLOBAL_POSTFIX", it is also subject to ARM service filename expansion,
  2125. in particular, it may contain "@{@}" (left and right curly brace)
  2126. sequence, which will be replaced by ARM with the name of the service.
  2127. This is used to keep logs from more than one service separate, while only
  2128. specifying one template containing "@{@}" in GLOBAL_POSTFIX.
  2129. As part of a secondary file name expansion, the first occurrence of "[]"
  2130. sequence ("left square brace" followed by "right square brace") in the
  2131. file name will be replaced with a process identifier or the process when
  2132. it initializes its logging subsystem. As a result, all processes will log
  2133. into different files. This is convenient for isolating messages of a
  2134. particular process, and prevents I/O races when multiple processes try to
  2135. write into the file at the same time. This expansion is done
  2136. independently of "@{@}" expansion that ARM service does (see above).
  2137. The log file name that is specified via "-l" can contain format characters
  2138. from the 'strftime' function family. For example, "%Y" will be replaced
  2139. with the current year. Using "basename-%Y-%m-%d.log" would include the
  2140. current year, month and day in the log file. If a GNUnet process runs for
  2141. long enough to need more than one log file, it will eventually clean up
  2142. old log files. Currently, only the last three log files (plus the current
  2143. log file) are preserved. So once the fifth log file goes into use (so
  2144. after 4 days if you use "%Y-%m-%d" as above), the first log file will be
  2145. automatically deleted. Note that if your log file name only contains "%Y",
  2146. then log files would be kept for 4 years and the logs from the first year
  2147. would be deleted once year 5 begins. If you do not use any date-related
  2148. string format codes, logs would never be automatically deleted by GNUnet.
  2149. @c ***********************************************************************
  2150. @node Updated behavior of GNUNET_log
  2151. @subsubsection Updated behavior of GNUNET_log
  2152. It's currently quite common to see constructions like this all over the
  2153. code:
  2154. @example
  2155. #if MESH_DEBUG
  2156. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n");
  2157. #endif
  2158. @end example
  2159. The reason for the #if is not to avoid displaying the message when
  2160. disabled (GNUNET_ERROR_TYPE takes care of that), but to avoid the
  2161. compiler including it in the binary at all, when compiling GNUnet for
  2162. platforms with restricted storage space / memory (MIPS routers,
  2163. ARM plug computers / dev boards, etc).
  2164. This presents several problems: the code gets ugly, hard to write and it
  2165. is very easy to forget to include the #if guards, creating non-consistent
  2166. code. A new change in GNUNET_log aims to solve these problems.
  2167. @strong{This change requires to @file{./configure} with at least
  2168. @code{--enable-logging=verbose} to see debug messages.}
  2169. Here is an example of code with dense debug statements:
  2170. @example
  2171. switch (restrict_topology) @{
  2172. case GNUNET_TESTING_TOPOLOGY_CLIQUE:#if VERBOSE_TESTING
  2173. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Blacklisting all but clique
  2174. topology\n")); #endif unblacklisted_connections = create_clique (pg,
  2175. &remove_connections, BLACKLIST, GNUNET_NO); break; case
  2176. GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: #if VERBOSE_TESTING GNUNET_log
  2177. (GNUNET_ERROR_TYPE_DEBUG, _("Blacklisting all but small world (ring)
  2178. topology\n")); #endif unblacklisted_connections = create_small_world_ring
  2179. (pg,&remove_connections, BLACKLIST); break;
  2180. @end example
  2181. Pretty hard to follow, huh?
  2182. From now on, it is not necessary to include the #if / #endif statements to
  2183. achieve the same behavior. The @code{GNUNET_log} and @code{GNUNET_log_from}
  2184. macros take care of it for you, depending on the configure option:
  2185. @itemize @bullet
  2186. @item If @code{--enable-logging} is set to @code{no}, the binary will
  2187. contain no log messages at all.
  2188. @item If @code{--enable-logging} is set to @code{yes}, the binary will
  2189. contain no DEBUG messages, and therefore running with @command{-L DEBUG}
  2190. will have
  2191. no effect. Other messages (ERROR, WARNING, INFO, etc) will be included.
  2192. @item If @code{--enable-logging} is set to @code{verbose}, or
  2193. @code{veryverbose} the binary will contain DEBUG messages (still, it will
  2194. be necessary to run with @command{-L DEBUG} or set the DEBUG config option
  2195. to show them).
  2196. @end itemize
  2197. If you are a developer:
  2198. @itemize @bullet
  2199. @item please make sure that you @code{./configure
  2200. --enable-logging=@{verbose,veryverbose@}}, so you can see DEBUG messages.
  2201. @item please remove the @code{#if} statements around @code{GNUNET_log
  2202. (GNUNET_ERROR_TYPE_DEBUG, ...)} lines, to improve the readability of your
  2203. code.
  2204. @end itemize
  2205. Since now activating DEBUG automatically makes it VERBOSE and activates
  2206. @strong{all} debug messages by default, you probably want to use the
  2207. @uref{https://docs.gnunet.org/#Logging, https://docs.gnunet.org/#Logging}
  2208. functionality to filter only relevant messages.
  2209. A suitable configuration could be:
  2210. @example
  2211. $ export GNUNET_FORCE_LOG="^YOUR_SUBSYSTEM$;;;;DEBUG/;;;;WARNING"
  2212. @end example
  2213. Which will behave almost like enabling DEBUG in that subsystem before the
  2214. change. Of course you can adapt it to your particular needs, this is only
  2215. a quick example.
  2216. @cindex Interprocess communication API
  2217. @cindex ICP
  2218. @node Interprocess communication API (IPC)
  2219. @subsection Interprocess communication API (IPC)
  2220. In GNUnet a variety of new message types might be defined and used in
  2221. interprocess communication, in this tutorial we use the
  2222. @code{struct AddressLookupMessage} as a example to introduce how to
  2223. construct our own message type in GNUnet and how to implement the message
  2224. communication between service and client.
  2225. (Here, a client uses the @code{struct AddressLookupMessage} as a request
  2226. to ask the server to return the address of any other peer connecting to
  2227. the service.)
  2228. @c ***********************************************************************
  2229. @menu
  2230. * Define new message types::
  2231. * Define message struct::
  2232. * Client - Establish connection::
  2233. * Client - Initialize request message::
  2234. * Client - Send request and receive response::
  2235. * Server - Startup service::
  2236. * Server - Add new handles for specified messages::
  2237. * Server - Process request message::
  2238. * Server - Response to client::
  2239. * Server - Notification of clients::
  2240. * Conversion between Network Byte Order (Big Endian) and Host Byte Order::
  2241. @end menu
  2242. @node Define new message types
  2243. @subsubsection Define new message types
  2244. First of all, you should define the new message type in
  2245. @file{gnunet_protocols.h}:
  2246. @example
  2247. // Request to look addresses of peers in server.
  2248. #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP 29
  2249. // Response to the address lookup request.
  2250. #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY 30
  2251. @end example
  2252. @c ***********************************************************************
  2253. @node Define message struct
  2254. @subsubsection Define message struct
  2255. After the type definition, the specified message structure should also be
  2256. described in the header file, e.g. transport.h in our case.
  2257. @example
  2258. struct AddressLookupMessage @{
  2259. struct GNUNET_MessageHeader header;
  2260. int32_t numeric_only GNUNET_PACKED;
  2261. struct GNUNET_TIME_AbsoluteNBO timeout;
  2262. uint32_t addrlen GNUNET_PACKED;
  2263. /* followed by 'addrlen' bytes of the actual address, then
  2264. followed by the 0-terminated name of the transport */ @};
  2265. GNUNET_NETWORK_STRUCT_END
  2266. @end example
  2267. Please note @code{GNUNET_NETWORK_STRUCT_BEGIN} and @code{GNUNET_PACKED}
  2268. which both ensure correct alignment when sending structs over the network.
  2269. @menu
  2270. @end menu
  2271. @c ***********************************************************************
  2272. @node Client - Establish connection
  2273. @subsubsection Client - Establish connection
  2274. At first, on the client side, the underlying API is employed to create a
  2275. new connection to a service, in our example the transport service would be
  2276. connected.
  2277. @example
  2278. struct GNUNET_CLIENT_Connection *client;
  2279. client = GNUNET_CLIENT_connect ("transport", cfg);
  2280. @end example
  2281. @c ***********************************************************************
  2282. @node Client - Initialize request message
  2283. @subsubsection Client - Initialize request message
  2284. When the connection is ready, we initialize the message. In this step,
  2285. all the fields of the message should be properly initialized, namely the
  2286. size, type, and some extra user-defined data, such as timeout, name of
  2287. transport, address and name of transport.
  2288. @example
  2289. struct AddressLookupMessage *msg;
  2290. size_t len = sizeof (struct AddressLookupMessage)
  2291. + addressLen
  2292. + strlen (nameTrans)
  2293. + 1;
  2294. msg->header->size = htons (len);
  2295. msg->header->type = htons
  2296. (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
  2297. msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout);
  2298. msg->addrlen = htonl (addressLen);
  2299. char *addrbuf = (char *) &msg[1];
  2300. memcpy (addrbuf, address, addressLen);
  2301. char *tbuf = &addrbuf[addressLen];
  2302. memcpy (tbuf, nameTrans, strlen (nameTrans) + 1);
  2303. @end example
  2304. Note that, here the functions @code{htonl}, @code{htons} and
  2305. @code{GNUNET_TIME_absolute_hton} are applied to convert little endian
  2306. into big endian, about the usage of the big/small endian order and the
  2307. corresponding conversion function please refer to Introduction of
  2308. Big Endian and Little Endian.
  2309. @c ***********************************************************************
  2310. @node Client - Send request and receive response
  2311. @subsubsection Client - Send request and receive response
  2312. @b{FIXME: This is very outdated, see the tutorial for the current API!}
  2313. Next, the client would send the constructed message as a request to the
  2314. service and wait for the response from the service. To accomplish this
  2315. goal, there are a number of API calls that can be used. In this example,
  2316. @code{GNUNET_CLIENT_transmit_and_get_response} is chosen as the most
  2317. appropriate function to use.
  2318. @example
  2319. GNUNET_CLIENT_transmit_and_get_response
  2320. (client, msg->header, timeout, GNUNET_YES, &address_response_processor,
  2321. arp_ctx);
  2322. @end example
  2323. the argument @code{address_response_processor} is a function with
  2324. @code{GNUNET_CLIENT_MessageHandler} type, which is used to process the
  2325. reply message from the service.
  2326. @node Server - Startup service
  2327. @subsubsection Server - Startup service
  2328. After receiving the request message, we run a standard GNUnet service
  2329. startup sequence using @code{GNUNET_SERVICE_run}, as follows,
  2330. @example
  2331. int main(int argc, char**argv) @{
  2332. GNUNET_SERVICE_run(argc, argv, "transport"
  2333. GNUNET_SERVICE_OPTION_NONE, &run, NULL)); @}
  2334. @end example
  2335. @c ***********************************************************************
  2336. @node Server - Add new handles for specified messages
  2337. @subsubsection Server - Add new handles for specified messages
  2338. in the function above the argument @code{run} is used to initiate
  2339. transport service,and defined like this:
  2340. @example
  2341. static void run (void *cls,
  2342. struct GNUNET_SERVER_Handle *serv,
  2343. const struct GNUNET_CONFIGURATION_Handle *cfg) @{
  2344. GNUNET_SERVER_add_handlers (serv, handlers); @}
  2345. @end example
  2346. Here, @code{GNUNET_SERVER_add_handlers} must be called in the run
  2347. function to add new handlers in the service. The parameter
  2348. @code{handlers} is a list of @code{struct GNUNET_SERVER_MessageHandler}
  2349. to tell the service which function should be called when a particular
  2350. type of message is received, and should be defined in this way:
  2351. @example
  2352. static struct GNUNET_SERVER_MessageHandler handlers[] = @{
  2353. @{&handle_start,
  2354. NULL,
  2355. GNUNET_MESSAGE_TYPE_TRANSPORT_START,
  2356. 0@},
  2357. @{&handle_send,
  2358. NULL,
  2359. GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
  2360. 0@},
  2361. @{&handle_try_connect,
  2362. NULL,
  2363. GNUNET_MESSAGE_TYPE_TRANSPORT_TRY_CONNECT,
  2364. sizeof (struct TryConnectMessage)
  2365. @},
  2366. @{&handle_address_lookup,
  2367. NULL,
  2368. GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP,
  2369. 0@},
  2370. @{NULL,
  2371. NULL,
  2372. 0,
  2373. 0@}
  2374. @};
  2375. @end example
  2376. As shown, the first member of the struct in the first area is a callback
  2377. function, which is called to process the specified message types, given
  2378. as the third member. The second parameter is the closure for the callback
  2379. function, which is set to @code{NULL} in most cases, and the last
  2380. parameter is the expected size of the message of this type, usually we
  2381. set it to 0 to accept variable size, for special cases the exact size of
  2382. the specified message also can be set. In addition, the terminator sign
  2383. depicted as @code{@{NULL, NULL, 0, 0@}} is set in the last area.
  2384. @c ***********************************************************************
  2385. @node Server - Process request message
  2386. @subsubsection Server - Process request message
  2387. After the initialization of transport service, the request message would
  2388. be processed. Before handling the main message data, the validity of this
  2389. message should be checked out, e.g., to check whether the size of message
  2390. is correct.
  2391. @example
  2392. size = ntohs (message->size);
  2393. if (size < sizeof (struct AddressLookupMessage)) @{
  2394. GNUNET_break_op (0);
  2395. GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
  2396. return; @}
  2397. @end example
  2398. Note that, opposite to the construction method of the request message in
  2399. the client, in the server the function @code{nothl} and @code{ntohs}
  2400. should be employed during the extraction of the data from the message, so
  2401. that the data in big endian order can be converted back into little
  2402. endian order. See more in detail please refer to Introduction of
  2403. Big Endian and Little Endian.
  2404. Moreover in this example, the name of the transport stored in the message
  2405. is a 0-terminated string, so we should also check whether the name of the
  2406. transport in the received message is 0-terminated:
  2407. @example
  2408. nameTransport = (const char *) &address[addressLen];
  2409. if (nameTransport[size - sizeof
  2410. (struct AddressLookupMessage)
  2411. - addressLen - 1] != '\0') @{
  2412. GNUNET_break_op (0);
  2413. GNUNET_SERVER_receive_done (client,
  2414. GNUNET_SYSERR);
  2415. return; @}
  2416. @end example
  2417. Here, @code{GNUNET_SERVER_receive_done} should be called to tell the
  2418. service that the request is done and can receive the next message. The
  2419. argument @code{GNUNET_SYSERR} here indicates that the service didn't
  2420. understand the request message, and the processing of this request would
  2421. be terminated.
  2422. In comparison to the aforementioned situation, when the argument is equal
  2423. to @code{GNUNET_OK}, the service would continue to process the request
  2424. message.
  2425. @c ***********************************************************************
  2426. @node Server - Response to client
  2427. @subsubsection Server - Response to client
  2428. Once the processing of current request is done, the server should give the
  2429. response to the client. A new @code{struct AddressLookupMessage} would be
  2430. produced by the server in a similar way as the client did and sent to the
  2431. client, but here the type should be
  2432. @code{GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY} rather than
  2433. @code{GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP} in client.
  2434. @example
  2435. struct AddressLookupMessage *msg;
  2436. size_t len = sizeof (struct AddressLookupMessage)
  2437. + addressLen
  2438. + strlen (nameTrans) + 1;
  2439. msg->header->size = htons (len);
  2440. msg->header->type = htons
  2441. (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
  2442. // ...
  2443. struct GNUNET_SERVER_TransmitContext *tc;
  2444. tc = GNUNET_SERVER_transmit_context_create (client);
  2445. GNUNET_SERVER_transmit_context_append_data
  2446. (tc,
  2447. NULL,
  2448. 0,
  2449. GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
  2450. GNUNET_SERVER_transmit_context_run (tc, rtimeout);
  2451. @end example
  2452. Note that, there are also a number of other APIs provided to the service
  2453. to send the message.
  2454. @c ***********************************************************************
  2455. @node Server - Notification of clients
  2456. @subsubsection Server - Notification of clients
  2457. Often a service needs to (repeatedly) transmit notifications to a client
  2458. or a group of clients. In these cases, the client typically has once
  2459. registered for a set of events and then needs to receive a message
  2460. whenever such an event happens (until the client disconnects). The use of
  2461. a notification context can help manage message queues to clients and
  2462. handle disconnects. Notification contexts can be used to send
  2463. individualized messages to a particular client or to broadcast messages
  2464. to a group of clients. An individualized notification might look like
  2465. this:
  2466. @example
  2467. GNUNET_SERVER_notification_context_unicast(nc,
  2468. client,
  2469. msg,
  2470. GNUNET_YES);
  2471. @end example
  2472. Note that after processing the original registration message for
  2473. notifications, the server code still typically needs to call
  2474. @code{GNUNET_SERVER_receive_done} so that the client can transmit further
  2475. messages to the server.
  2476. @c ***********************************************************************
  2477. @node Conversion between Network Byte Order (Big Endian) and Host Byte Order
  2478. @subsubsection Conversion between Network Byte Order (Big Endian) and Host Byte Order
  2479. @c %** subsub? it's a referenced page on the ipc document.
  2480. Here we can simply comprehend big endian and little endian as Network Byte
  2481. Order and Host Byte Order respectively. What is the difference between
  2482. both two?
  2483. Usually in our host computer we store the data byte as Host Byte Order,
  2484. for example, we store a integer in the RAM which might occupies 4 Byte,
  2485. as Host Byte Order the higher Byte would be stored at the lower address
  2486. of RAM, and the lower Byte would be stored at the higher address of RAM.
  2487. However, contrast to this, Network Byte Order just take the totally
  2488. opposite way to store the data, says, it will store the lower Byte at the
  2489. lower address, and the higher Byte will stay at higher address.
  2490. For the current communication of network, we normally exchange the
  2491. information by surveying the data package, every two host wants to
  2492. communicate with each other must send and receive data package through
  2493. network. In order to maintain the identity of data through the
  2494. transmission in the network, the order of the Byte storage must changed
  2495. before sending and after receiving the data.
  2496. There ten convenient functions to realize the conversion of Byte Order in
  2497. GNUnet, as following:
  2498. @table @asis
  2499. @item uint16_t htons(uint16_t hostshort) Convert host byte order to net
  2500. byte order with short int
  2501. @item uint32_t htonl(uint32_t hostlong) Convert host byte
  2502. order to net byte order with long int
  2503. @item uint16_t ntohs(uint16_t netshort)
  2504. Convert net byte order to host byte order with short int
  2505. @item uint32_t
  2506. ntohl(uint32_t netlong) Convert net byte order to host byte order with
  2507. long int
  2508. @item unsigned long long GNUNET_ntohll (unsigned long long netlonglong)
  2509. Convert net byte order to host byte order with long long int
  2510. @item unsigned long long GNUNET_htonll (unsigned long long hostlonglong)
  2511. Convert host byte order to net byte order with long long int
  2512. @item struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton
  2513. (struct GNUNET_TIME_Relative a) Convert relative time to network byte
  2514. order.
  2515. @item struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh
  2516. (struct GNUNET_TIME_RelativeNBO a) Convert relative time from network
  2517. byte order.
  2518. @item struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton
  2519. (struct GNUNET_TIME_Absolute a) Convert relative time to network byte
  2520. order.
  2521. @item struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh
  2522. (struct GNUNET_TIME_AbsoluteNBO a) Convert relative time from network
  2523. byte order.
  2524. @end table
  2525. @cindex Cryptography API
  2526. @node Cryptography API
  2527. @subsection Cryptography API
  2528. The gnunetutil APIs provides the cryptographic primitives used in GNUnet.
  2529. GNUnet uses 2048 bit RSA keys for the session key exchange and for signing
  2530. messages by peers and most other public-key operations. Most researchers
  2531. in cryptography consider 2048 bit RSA keys as secure and practically
  2532. unbreakable for a long time. The API provides functions to create a fresh
  2533. key pair, read a private key from a file (or create a new file if the
  2534. file does not exist), encrypt, decrypt, sign, verify and extraction of
  2535. the public key into a format suitable for network transmission.
  2536. For the encryption of files and the actual data exchanged between peers
  2537. GNUnet uses 256-bit AES encryption. Fresh, session keys are negotiated
  2538. for every new connection.@ Again, there is no published technique to
  2539. break this cipher in any realistic amount of time. The API provides
  2540. functions for generation of keys, validation of keys (important for
  2541. checking that decryptions using RSA succeeded), encryption and decryption.
  2542. GNUnet uses SHA-512 for computing one-way hash codes. The API provides
  2543. functions to compute a hash over a block in memory or over a file on disk.
  2544. The crypto API also provides functions for randomizing a block of memory,
  2545. obtaining a single random number and for generating a permutation of the
  2546. numbers 0 to n-1. Random number generation distinguishes between WEAK and
  2547. STRONG random number quality; WEAK random numbers are pseudo-random
  2548. whereas STRONG random numbers use entropy gathered from the operating
  2549. system.
  2550. Finally, the crypto API provides a means to deterministically generate a
  2551. 1024-bit RSA key from a hash code. These functions should most likely not
  2552. be used by most applications; most importantly,
  2553. GNUNET_CRYPTO_rsa_key_create_from_hash does not create an RSA-key that
  2554. should be considered secure for traditional applications of RSA.
  2555. @cindex Message Queue API
  2556. @node Message Queue API
  2557. @subsection Message Queue API
  2558. @strong{ Introduction }@
  2559. Often, applications need to queue messages that
  2560. are to be sent to other GNUnet peers, clients or services. As all of
  2561. GNUnet's message-based communication APIs, by design, do not allow
  2562. messages to be queued, it is common to implement custom message queues
  2563. manually when they are needed. However, writing very similar code in
  2564. multiple places is tedious and leads to code duplication.
  2565. MQ (for Message Queue) is an API that provides the functionality to
  2566. implement and use message queues. We intend to eventually replace all of
  2567. the custom message queue implementations in GNUnet with MQ.
  2568. @strong{ Basic Concepts }@
  2569. The two most important entities in MQ are queues and envelopes.
  2570. Every queue is backed by a specific implementation (e.g. for mesh, stream,
  2571. connection, server client, etc.) that will actually deliver the queued
  2572. messages. For convenience,@ some queues also allow to specify a list of
  2573. message handlers. The message queue will then also wait for incoming
  2574. messages and dispatch them appropriately.
  2575. An envelope holds the memory for a message, as well as metadata
  2576. (Where is the envelope queued? What should happen after it has been
  2577. sent?). Any envelope can only be queued in one message queue.
  2578. @strong{ Creating Queues }@
  2579. The following is a list of currently available message queues. Note that
  2580. to avoid layering issues, message queues for higher level APIs are not
  2581. part of @code{libgnunetutil}, but@ the respective API itself provides the
  2582. queue implementation.
  2583. @table @asis
  2584. @item @code{GNUNET_MQ_queue_for_connection_client}
  2585. Transmits queued messages over a @code{GNUNET_CLIENT_Connection} handle.
  2586. Also supports receiving with message handlers.
  2587. @item @code{GNUNET_MQ_queue_for_server_client}
  2588. Transmits queued messages over a @code{GNUNET_SERVER_Client} handle. Does
  2589. not support incoming message handlers.
  2590. @item @code{GNUNET_MESH_mq_create} Transmits queued messages over a
  2591. @code{GNUNET_MESH_Tunnel} handle. Does not support incoming message
  2592. handlers.
  2593. @item @code{GNUNET_MQ_queue_for_callbacks} This is the most general
  2594. implementation. Instead of delivering and receiving messages with one of
  2595. GNUnet's communication APIs, implementation callbacks are called. Refer to
  2596. "Implementing Queues" for a more detailed explanation.
  2597. @end table
  2598. @strong{ Allocating Envelopes }@
  2599. A GNUnet message (as defined by the GNUNET_MessageHeader) has three
  2600. parts: The size, the type, and the body.
  2601. MQ provides macros to allocate an envelope containing a message
  2602. conveniently, automatically setting the size and type fields of the
  2603. message.
  2604. Consider the following simple message, with the body consisting of a
  2605. single number value.
  2606. @c why the empty code function?
  2607. @code{}
  2608. @example
  2609. struct NumberMessage @{
  2610. /** Type: GNUNET_MESSAGE_TYPE_EXAMPLE_1 */
  2611. struct GNUNET_MessageHeader header;
  2612. uint32_t number GNUNET_PACKED;
  2613. @};
  2614. @end example
  2615. An envelope containing an instance of the NumberMessage can be
  2616. constructed like this:
  2617. @example
  2618. struct GNUNET_MQ_Envelope *ev;
  2619. struct NumberMessage *msg;
  2620. ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_EXAMPLE_1);
  2621. msg->number = htonl (42);
  2622. @end example
  2623. In the above code, @code{GNUNET_MQ_msg} is a macro. The return value is
  2624. the newly allocated envelope. The first argument must be a pointer to some
  2625. @code{struct} containing a @code{struct GNUNET_MessageHeader header}
  2626. field, while the second argument is the desired message type, in host
  2627. byte order.
  2628. The @code{msg} pointer now points to an allocated message, where the
  2629. message type and the message size are already set. The message's size is
  2630. inferred from the type of the @code{msg} pointer: It will be set to
  2631. 'sizeof(*msg)', properly converted to network byte order.
  2632. If the message body's size is dynamic, then the macro
  2633. @code{GNUNET_MQ_msg_extra} can be used to allocate an envelope whose
  2634. message has additional space allocated after the @code{msg} structure.
  2635. If no structure has been defined for the message,
  2636. @code{GNUNET_MQ_msg_header_extra} can be used to allocate additional space
  2637. after the message header. The first argument then must be a pointer to a
  2638. @code{GNUNET_MessageHeader}.
  2639. @strong{Envelope Properties}@
  2640. A few functions in MQ allow to set additional properties on envelopes:
  2641. @table @asis
  2642. @item @code{GNUNET_MQ_notify_sent} Allows to specify a function that will
  2643. be called once the envelope's message has been sent irrevocably.
  2644. An envelope can be canceled precisely up to the@ point where the notify
  2645. sent callback has been called.
  2646. @item @code{GNUNET_MQ_disable_corking} No corking will be used when
  2647. sending the message. Not every@ queue supports this flag, per default,
  2648. envelopes are sent with corking.@
  2649. @end table
  2650. @strong{Sending Envelopes}@
  2651. Once an envelope has been constructed, it can be queued for sending with
  2652. @code{GNUNET_MQ_send}.
  2653. Note that in order to avoid memory leaks, an envelope must either be sent
  2654. (the queue will free it) or destroyed explicitly with
  2655. @code{GNUNET_MQ_discard}.
  2656. @strong{Canceling Envelopes}@
  2657. An envelope queued with @code{GNUNET_MQ_send} can be canceled with
  2658. @code{GNUNET_MQ_cancel}. Note that after the notify sent callback has
  2659. been called, canceling a message results in undefined behavior.
  2660. Thus it is unsafe to cancel an envelope that does not have a notify sent
  2661. callback. When canceling an envelope, it is not necessary@ to call
  2662. @code{GNUNET_MQ_discard}, and the envelope can't be sent again.
  2663. @strong{ Implementing Queues }@
  2664. @code{TODO}
  2665. @cindex Service API
  2666. @node Service API
  2667. @subsection Service API
  2668. Most GNUnet code lives in the form of services. Services are processes
  2669. that offer an API for other components of the system to build on. Those
  2670. other components can be command-line tools for users, graphical user
  2671. interfaces or other services. Services provide their API using an IPC
  2672. protocol. For this, each service must listen on either a TCP port or a
  2673. UNIX domain socket; for this, the service implementation uses the server
  2674. API. This use of server is exposed directly to the users of the service
  2675. API. Thus, when using the service API, one is usually also often using
  2676. large parts of the server API. The service API provides various
  2677. convenience functions, such as parsing command-line arguments and the
  2678. configuration file, which are not found in the server API.
  2679. The dual to the service/server API is the client API, which can be used to
  2680. access services.
  2681. The most common way to start a service is to use the
  2682. @code{GNUNET_SERVICE_run} function from the program's main function.
  2683. @code{GNUNET_SERVICE_run} will then parse the command line and
  2684. configuration files and, based on the options found there,
  2685. start the server. It will then give back control to the main
  2686. program, passing the server and the configuration to the
  2687. @code{GNUNET_SERVICE_Main} callback. @code{GNUNET_SERVICE_run}
  2688. will also take care of starting the scheduler loop.
  2689. If this is inappropriate (for example, because the scheduler loop
  2690. is already running), @code{GNUNET_SERVICE_start} and
  2691. related functions provide an alternative to @code{GNUNET_SERVICE_run}.
  2692. When starting a service, the service_name option is used to determine
  2693. which sections in the configuration file should be used to configure the
  2694. service. A typical value here is the name of the @file{src/}
  2695. sub-directory, for example @file{statistics}.
  2696. The same string would also be given to
  2697. @code{GNUNET_CLIENT_connect} to access the service.
  2698. Once a service has been initialized, the program should use the
  2699. @code{GNUNET_SERVICE_Main} callback to register message handlers
  2700. using @code{GNUNET_SERVER_add_handlers}.
  2701. The service will already have registered a handler for the
  2702. "TEST" message.
  2703. @findex GNUNET_SERVICE_Options
  2704. The option bitfield (@code{enum GNUNET_SERVICE_Options})
  2705. determines how a service should behave during shutdown.
  2706. There are three key strategies:
  2707. @table @asis
  2708. @item instant (@code{GNUNET_SERVICE_OPTION_NONE})
  2709. Upon receiving the shutdown
  2710. signal from the scheduler, the service immediately terminates the server,
  2711. closing all existing connections with clients.
  2712. @item manual (@code{GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN})
  2713. The service does nothing by itself
  2714. during shutdown. The main program will need to take the appropriate
  2715. action by calling GNUNET_SERVER_destroy or GNUNET_SERVICE_stop (depending
  2716. on how the service was initialized) to terminate the service. This method
  2717. is used by gnunet-service-arm and rather uncommon.
  2718. @item soft (@code{GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN})
  2719. Upon receiving the shutdown signal from the scheduler,
  2720. the service immediately tells the server to stop
  2721. listening for incoming clients. Requests from normal existing clients are
  2722. still processed and the server/service terminates once all normal clients
  2723. have disconnected. Clients that are not expected to ever disconnect (such
  2724. as clients that monitor performance values) can be marked as 'monitor'
  2725. clients using GNUNET_SERVER_client_mark_monitor. Those clients will
  2726. continue to be processed until all 'normal' clients have disconnected.
  2727. Then, the server will terminate, closing the monitor connections.
  2728. This mode is for example used by 'statistics', allowing existing 'normal'
  2729. clients to set (possibly persistent) statistic values before terminating.
  2730. @end table
  2731. @c ***********************************************************************
  2732. @node Optimizing Memory Consumption of GNUnet's (Multi-) Hash Maps
  2733. @subsection Optimizing Memory Consumption of GNUnet's (Multi-) Hash Maps
  2734. A commonly used data structure in GNUnet is a (multi-)hash map. It is most
  2735. often used to map a peer identity to some data structure, but also to map
  2736. arbitrary keys to values (for example to track requests in the distributed
  2737. hash table or in file-sharing). As it is commonly used, the DHT is
  2738. actually sometimes responsible for a large share of GNUnet's overall
  2739. memory consumption (for some processes, 30% is not uncommon). The
  2740. following text documents some API quirks (and their implications for
  2741. applications) that were recently introduced to minimize the footprint of
  2742. the hash map.
  2743. @c ***********************************************************************
  2744. @menu
  2745. * Analysis::
  2746. * Solution::
  2747. * Migration::
  2748. * Conclusion::
  2749. * Availability::
  2750. @end menu
  2751. @node Analysis
  2752. @subsubsection Analysis
  2753. The main reason for the "excessive" memory consumption by the hash map is
  2754. that GNUnet uses 512-bit cryptographic hash codes --- and the
  2755. (multi-)hash map also uses the same 512-bit 'struct GNUNET_HashCode'. As
  2756. a result, storing just the keys requires 64 bytes of memory for each key.
  2757. As some applications like to keep a large number of entries in the hash
  2758. map (after all, that's what maps are good for), 64 bytes per hash is
  2759. significant: keeping a pointer to the value and having a linked list for
  2760. collisions consume between 8 and 16 bytes, and 'malloc' may add about the
  2761. same overhead per allocation, putting us in the 16 to 32 byte per entry
  2762. ballpark. Adding a 64-byte key then triples the overall memory
  2763. requirement for the hash map.
  2764. To make things "worse", most of the time storing the key in the hash map
  2765. is not required: it is typically already in memory elsewhere! In most
  2766. cases, the values stored in the hash map are some application-specific
  2767. struct that _also_ contains the hash. Here is a simplified example:
  2768. @example
  2769. struct MyValue @{
  2770. struct GNUNET_HashCode key;
  2771. unsigned int my_data; @};
  2772. // ...
  2773. val = GNUNET_malloc (sizeof (struct MyValue));
  2774. val->key = key;
  2775. val->my_data = 42;
  2776. GNUNET_CONTAINER_multihashmap_put (map, &key, val, ...);
  2777. @end example
  2778. This is a common pattern as later the entries might need to be removed,
  2779. and at that time it is convenient to have the key immediately at hand:
  2780. @example
  2781. GNUNET_CONTAINER_multihashmap_remove (map, &val->key, val);
  2782. @end example
  2783. Note that here we end up with two times 64 bytes for the key, plus maybe
  2784. 64 bytes total for the rest of the 'struct MyValue' and the map entry in
  2785. the hash map. The resulting redundant storage of the key increases
  2786. overall memory consumption per entry from the "optimal" 128 bytes to 192
  2787. bytes. This is not just an extreme example: overheads in practice are
  2788. actually sometimes close to those highlighted in this example. This is
  2789. especially true for maps with a significant number of entries, as there
  2790. we tend to really try to keep the entries small.
  2791. @c ***********************************************************************
  2792. @node Solution
  2793. @subsubsection Solution
  2794. The solution that has now been implemented is to @strong{optionally}
  2795. allow the hash map to not make a (deep) copy of the hash but instead have
  2796. a pointer to the hash/key in the entry. This reduces the memory
  2797. consumption for the key from 64 bytes to 4 to 8 bytes. However, it can
  2798. also only work if the key is actually stored in the entry (which is the
  2799. case most of the time) and if the entry does not modify the key (which in
  2800. all of the code I'm aware of has been always the case if there key is
  2801. stored in the entry). Finally, when the client stores an entry in the
  2802. hash map, it @strong{must} provide a pointer to the key within the entry,
  2803. not just a pointer to a transient location of the key. If
  2804. the client code does not meet these requirements, the result is a dangling
  2805. pointer and undefined behavior of the (multi-)hash map API.
  2806. @c ***********************************************************************
  2807. @node Migration
  2808. @subsubsection Migration
  2809. To use the new feature, first check that the values contain the respective
  2810. key (and never modify it). Then, all calls to
  2811. @code{GNUNET_CONTAINER_multihashmap_put} on the respective map must be
  2812. audited and most likely changed to pass a pointer into the value's struct.
  2813. For the initial example, the new code would look like this:
  2814. @example
  2815. struct MyValue @{
  2816. struct GNUNET_HashCode key;
  2817. unsigned int my_data; @};
  2818. // ...
  2819. val = GNUNET_malloc (sizeof (struct MyValue));
  2820. val->key = key; val->my_data = 42;
  2821. GNUNET_CONTAINER_multihashmap_put (map, &val->key, val, ...);
  2822. @end example
  2823. Note that @code{&val} was changed to @code{&val->key} in the argument to
  2824. the @code{put} call. This is critical as often @code{key} is on the stack
  2825. or in some other transient data structure and thus having the hash map
  2826. keep a pointer to @code{key} would not work. Only the key inside of
  2827. @code{val} has the same lifetime as the entry in the map (this must of
  2828. course be checked as well). Naturally, @code{val->key} must be
  2829. initialized before the @code{put} call. Once all @code{put} calls have
  2830. been converted and double-checked, you can change the call to create the
  2831. hash map from
  2832. @example
  2833. map =
  2834. GNUNET_CONTAINER_multihashmap_create (SIZE, GNUNET_NO);
  2835. @end example
  2836. to
  2837. @example
  2838. map = GNUNET_CONTAINER_multihashmap_create (SIZE, GNUNET_YES);
  2839. @end example
  2840. If everything was done correctly, you now use about 60 bytes less memory
  2841. per entry in @code{map}. However, if now (or in the future) any call to
  2842. @code{put} does not ensure that the given key is valid until the entry is
  2843. removed from the map, undefined behavior is likely to be observed.
  2844. @c ***********************************************************************
  2845. @node Conclusion
  2846. @subsubsection Conclusion
  2847. The new optimization can is often applicable and can result in a
  2848. reduction in memory consumption of up to 30% in practice. However, it
  2849. makes the code less robust as additional invariants are imposed on the
  2850. multi hash map client. Thus applications should refrain from enabling the
  2851. new mode unless the resulting performance increase is deemed significant
  2852. enough. In particular, it should generally not be used in new code (wait
  2853. at least until benchmarks exist).
  2854. @c ***********************************************************************
  2855. @node Availability
  2856. @subsubsection Availability
  2857. The new multi hash map code was committed in SVN 24319 (which made its
  2858. way into GNUnet version 0.9.4).
  2859. Various subsystems (transport, core, dht, file-sharing) were
  2860. previously audited and modified to take advantage of the new capability.
  2861. In particular, memory consumption of the file-sharing service is expected
  2862. to drop by 20-30% due to this change.
  2863. @cindex CONTAINER_MDLL API
  2864. @node CONTAINER_MDLL API
  2865. @subsection CONTAINER_MDLL API
  2866. This text documents the GNUNET_CONTAINER_MDLL API. The
  2867. GNUNET_CONTAINER_MDLL API is similar to the GNUNET_CONTAINER_DLL API in
  2868. that it provides operations for the construction and manipulation of
  2869. doubly-linked lists. The key difference to the (simpler) DLL-API is that
  2870. the MDLL-version allows a single element (instance of a "struct") to be
  2871. in multiple linked lists at the same time.
  2872. Like the DLL API, the MDLL API stores (most of) the data structures for
  2873. the doubly-linked list with the respective elements; only the 'head' and
  2874. 'tail' pointers are stored "elsewhere" --- and the application needs to
  2875. provide the locations of head and tail to each of the calls in the
  2876. MDLL API. The key difference for the MDLL API is that the "next" and
  2877. "previous" pointers in the struct can no longer be simply called "next"
  2878. and "prev" --- after all, the element may be in multiple doubly-linked
  2879. lists, so we cannot just have one "next" and one "prev" pointer!
  2880. The solution is to have multiple fields that must have a name of the
  2881. format "next_XX" and "prev_XX" where "XX" is the name of one of the
  2882. doubly-linked lists. Here is a simple example:
  2883. @example
  2884. struct MyMultiListElement @{
  2885. struct MyMultiListElement *next_ALIST;
  2886. struct MyMultiListElement *prev_ALIST;
  2887. struct MyMultiListElement *next_BLIST;
  2888. struct MyMultiListElement *prev_BLIST;
  2889. void
  2890. *data;
  2891. @};
  2892. @end example
  2893. Note that by convention, we use all-uppercase letters for the list names.
  2894. In addition, the program needs to have a location for the head and tail
  2895. pointers for both lists, for example:
  2896. @example
  2897. static struct MyMultiListElement *head_ALIST;
  2898. static struct MyMultiListElement *tail_ALIST;
  2899. static struct MyMultiListElement *head_BLIST;
  2900. static struct MyMultiListElement *tail_BLIST;
  2901. @end example
  2902. Using the MDLL-macros, we can now insert an element into the ALIST:
  2903. @example
  2904. GNUNET_CONTAINER_MDLL_insert (ALIST, head_ALIST, tail_ALIST, element);
  2905. @end example
  2906. Passing "ALIST" as the first argument to MDLL specifies which of the
  2907. next/prev fields in the 'struct MyMultiListElement' should be used. The
  2908. extra "ALIST" argument and the "_ALIST" in the names of the
  2909. next/prev-members are the only differences between the MDDL and DLL-API.
  2910. Like the DLL-API, the MDLL-API offers functions for inserting (at head,
  2911. at tail, after a given element) and removing elements from the list.
  2912. Iterating over the list should be done by directly accessing the
  2913. "next_XX" and/or "prev_XX" members.
  2914. @cindex Automatic Restart Manager
  2915. @cindex ARM
  2916. @node Automatic Restart Manager (ARM)
  2917. @section Automatic Restart Manager (ARM)
  2918. GNUnet's Automated Restart Manager (ARM) is the GNUnet service responsible
  2919. for system initialization and service babysitting. ARM starts and halts
  2920. services, detects configuration changes and restarts services impacted by
  2921. the changes as needed. It's also responsible for restarting services in
  2922. case of crashes and is planned to incorporate automatic debugging for
  2923. diagnosing service crashes providing developers insights about crash
  2924. reasons. The purpose of this document is to give GNUnet developer an idea
  2925. about how ARM works and how to interact with it.
  2926. @menu
  2927. * Basic functionality::
  2928. * Key configuration options::
  2929. * ARM - Availability::
  2930. * Reliability::
  2931. @end menu
  2932. @c ***********************************************************************
  2933. @node Basic functionality
  2934. @subsection Basic functionality
  2935. @itemize @bullet
  2936. @item ARM source code can be found under "src/arm".@ Service processes are
  2937. managed by the functions in "gnunet-service-arm.c" which is controlled
  2938. with "gnunet-arm.c" (main function in that file is ARM's entry point).
  2939. @item The functions responsible for communicating with ARM , starting and
  2940. stopping services -including ARM service itself- are provided by the
  2941. ARM API "arm_api.c".@ Function: GNUNET_ARM_connect() returns to the caller
  2942. an ARM handle after setting it to the caller's context (configuration and
  2943. scheduler in use). This handle can be used afterwards by the caller to
  2944. communicate with ARM. Functions GNUNET_ARM_start_service() and
  2945. GNUNET_ARM_stop_service() are used for starting and stopping services
  2946. respectively.
  2947. @item A typical example of using these basic ARM services can be found in
  2948. file test_arm_api.c. The test case connects to ARM, starts it, then uses
  2949. it to start a service "resolver", stops the "resolver" then stops "ARM".
  2950. @end itemize
  2951. @c ***********************************************************************
  2952. @node Key configuration options
  2953. @subsection Key configuration options
  2954. Configurations for ARM and services should be available in a .conf file
  2955. (As an example, see test_arm_api_data.conf). When running ARM, the
  2956. configuration file to use should be passed to the command:
  2957. @example
  2958. $ gnunet-arm -s -c configuration_to_use.conf
  2959. @end example
  2960. If no configuration is passed, the default configuration file will be used
  2961. (see GNUNET_PREFIX/share/gnunet/defaults.conf which is created from
  2962. contrib/defaults.conf).@ Each of the services is having a section starting
  2963. by the service name between square brackets, for example: "[arm]".
  2964. The following options configure how ARM configures or interacts with the
  2965. various services:
  2966. @table @asis
  2967. @item PORT Port number on which the service is listening for incoming TCP
  2968. connections. ARM will start the services should it notice a request at
  2969. this port.
  2970. @item HOSTNAME Specifies on which host the service is deployed. Note
  2971. that ARM can only start services that are running on the local system
  2972. (but will not check that the hostname matches the local machine name).
  2973. This option is used by the @code{gnunet_client_lib.h} implementation to
  2974. determine which system to connect to. The default is "localhost".
  2975. @item BINARY The name of the service binary file.
  2976. @item OPTIONS To be passed to the service.
  2977. @item PREFIX A command to pre-pend to the actual command, for example,
  2978. running a service with "valgrind" or "gdb"
  2979. @item DEBUG Run in debug mode (much verbosity).
  2980. @item START_ON_DEMAND ARM will listen to UNIX domain socket and/or TCP port of
  2981. the service and start the service on-demand.
  2982. @item IMMEDIATE_START ARM will always start this service when the peer
  2983. is started.
  2984. @item ACCEPT_FROM IPv4 addresses the service accepts connections from.
  2985. @item ACCEPT_FROM6 IPv6 addresses the service accepts connections from.
  2986. @end table
  2987. Options that impact the operation of ARM overall are in the "[arm]"
  2988. section. ARM is a normal service and has (except for START_ON_DEMAND) all of the
  2989. options that other services do. In addition, ARM has the
  2990. following options:
  2991. @table @asis
  2992. @item GLOBAL_PREFIX Command to be pre-pended to all services that are
  2993. going to run.
  2994. @item GLOBAL_POSTFIX Global option that will be supplied to all the
  2995. services that are going to run.
  2996. @end table
  2997. @c ***********************************************************************
  2998. @node ARM - Availability
  2999. @subsection ARM - Availability
  3000. As mentioned before, one of the features provided by ARM is starting
  3001. services on demand. Consider the example of one service "client" that
  3002. wants to connect to another service a "server". The "client" will ask ARM
  3003. to run the "server". ARM starts the "server". The "server" starts
  3004. listening to incoming connections. The "client" will establish a
  3005. connection with the "server". And then, they will start to communicate
  3006. together.@ One problem with that scheme is that it's slow!@
  3007. The "client" service wants to communicate with the "server" service at
  3008. once and is not willing wait for it to be started and listening to
  3009. incoming connections before serving its request.@ One solution for that
  3010. problem will be that ARM starts all services as default services. That
  3011. solution will solve the problem, yet, it's not quite practical, for some
  3012. services that are going to be started can never be used or are going to
  3013. be used after a relatively long time.@
  3014. The approach followed by ARM to solve this problem is as follows:
  3015. @itemize @bullet
  3016. @item For each service having a PORT field in the configuration file and
  3017. that is not one of the default services ( a service that accepts incoming
  3018. connections from clients), ARM creates listening sockets for all addresses
  3019. associated with that service.
  3020. @item The "client" will immediately establish a connection with
  3021. the "server".
  3022. @item ARM --- pretending to be the "server" --- will listen on the
  3023. respective port and notice the incoming connection from the "client"
  3024. (but not accept it), instead
  3025. @item Once there is an incoming connection, ARM will start the "server",
  3026. passing on the listen sockets (now, the service is started and can do its
  3027. work).
  3028. @item Other client services now can directly connect directly to the
  3029. "server".
  3030. @end itemize
  3031. @c ***********************************************************************
  3032. @node Reliability
  3033. @subsection Reliability
  3034. One of the features provided by ARM, is the automatic restart of crashed
  3035. services.@ ARM needs to know which of the running services died. Function
  3036. "gnunet-service-arm.c/maint_child_death()" is responsible for that. The
  3037. function is scheduled to run upon receiving a SIGCHLD signal. The
  3038. function, then, iterates ARM's list of services running and monitors
  3039. which service has died (crashed). For all crashing services, ARM restarts
  3040. them.@
  3041. Now, considering the case of a service having a serious problem causing it
  3042. to crash each time it's started by ARM. If ARM keeps blindly restarting
  3043. such a service, we are going to have the pattern:
  3044. start-crash-restart-crash-restart-crash and so forth!! Which is of course
  3045. not practical.@
  3046. For that reason, ARM schedules the service to be restarted after waiting
  3047. for some delay that grows exponentially with each crash/restart of that
  3048. service.@ To clarify the idea, considering the following example:
  3049. @itemize @bullet
  3050. @item Service S crashed.
  3051. @item ARM receives the SIGCHLD and inspects its list of services to find
  3052. the dead one(s).
  3053. @item ARM finds S dead and schedules it for restarting after "backoff"
  3054. time which is initially set to 1ms. ARM will double the backoff time
  3055. correspondent to S (now backoff(S) = 2ms)
  3056. @item Because there is a severe problem with S, it crashed again.
  3057. @item Again ARM receives the SIGCHLD and detects that it's S again that's
  3058. crashed. ARM schedules it for restarting but after its new backoff time
  3059. (which became 2ms), and doubles its backoff time (now backoff(S) = 4).
  3060. @item and so on, until backoff(S) reaches a certain threshold
  3061. (@code{EXPONENTIAL_BACKOFF_THRESHOLD} is set to half an hour),
  3062. after reaching it, backoff(S) will remain half an hour,
  3063. hence ARM won't be busy for a lot of time trying to restart a
  3064. problematic service.
  3065. @end itemize
  3066. @cindex TRANSPORT Subsystem
  3067. @node TRANSPORT Subsystem
  3068. @section TRANSPORT Subsystem
  3069. This chapter documents how the GNUnet transport subsystem works. The
  3070. GNUnet transport subsystem consists of three main components: the
  3071. transport API (the interface used by the rest of the system to access the
  3072. transport service), the transport service itself (most of the interesting
  3073. functions, such as choosing transports, happens here) and the transport
  3074. plugins. A transport plugin is a concrete implementation for how two
  3075. GNUnet peers communicate; many plugins exist, for example for
  3076. communication via TCP, UDP, HTTP, HTTPS and others. Finally, the
  3077. transport subsystem uses supporting code, especially the NAT/UPnP
  3078. library to help with tasks such as NAT traversal.
  3079. Key tasks of the transport service include:
  3080. @itemize @bullet
  3081. @item Create our HELLO message, notify clients and neighbours if our HELLO
  3082. changes (using NAT library as necessary)
  3083. @item Validate HELLOs from other peers (send PING), allow other peers to
  3084. validate our HELLO's addresses (send PONG)
  3085. @item Upon request, establish connections to other peers (using address
  3086. selection from ATS subsystem) and maintain them (again using PINGs and
  3087. PONGs) as long as desired
  3088. @item Accept incoming connections, give ATS service the opportunity to
  3089. switch communication channels
  3090. @item Notify clients about peers that have connected to us or that have
  3091. been disconnected from us
  3092. @item If a (stateful) connection goes down unexpectedly (without explicit
  3093. DISCONNECT), quickly attempt to recover (without notifying clients) but do
  3094. notify clients quickly if reconnecting fails
  3095. @item Send (payload) messages arriving from clients to other peers via
  3096. transport plugins and receive messages from other peers, forwarding
  3097. those to clients
  3098. @item Enforce inbound traffic limits (using flow-control if it is
  3099. applicable); outbound traffic limits are enforced by CORE, not by us (!)
  3100. @item Enforce restrictions on P2P connection as specified by the blacklist
  3101. configuration and blacklisting clients
  3102. @end itemize
  3103. Note that the term "clients" in the list above really refers to the
  3104. GNUnet-CORE service, as CORE is typically the only client of the
  3105. transport service.
  3106. @menu
  3107. * Address validation protocol::
  3108. @end menu
  3109. @node Address validation protocol
  3110. @subsection Address validation protocol
  3111. This section documents how the GNUnet transport service validates
  3112. connections with other peers. It is a high-level description of the
  3113. protocol necessary to understand the details of the implementation. It
  3114. should be noted that when we talk about PING and PONG messages in this
  3115. section, we refer to transport-level PING and PONG messages, which are
  3116. different from core-level PING and PONG messages (both in implementation
  3117. and function).
  3118. The goal of transport-level address validation is to minimize the chances
  3119. of a successful man-in-the-middle attack against GNUnet peers on the
  3120. transport level. Such an attack would not allow the adversary to decrypt
  3121. the P2P transmissions, but a successful attacker could at least measure
  3122. traffic volumes and latencies (raising the adversaries capabilities by
  3123. those of a global passive adversary in the worst case). The scenarios we
  3124. are concerned about is an attacker, Mallory, giving a @code{HELLO} to
  3125. Alice that claims to be for Bob, but contains Mallory's IP address
  3126. instead of Bobs (for some transport).
  3127. Mallory would then forward the traffic to Bob (by initiating a
  3128. connection to Bob and claiming to be Alice). As a further
  3129. complication, the scheme has to work even if say Alice is behind a NAT
  3130. without traversal support and hence has no address of her own (and thus
  3131. Alice must always initiate the connection to Bob).
  3132. An additional constraint is that @code{HELLO} messages do not contain a
  3133. cryptographic signature since other peers must be able to edit
  3134. (i.e. remove) addresses from the @code{HELLO} at any time (this was
  3135. not true in GNUnet 0.8.x). A basic @strong{assumption} is that each peer
  3136. knows the set of possible network addresses that it @strong{might}
  3137. be reachable under (so for example, the external IP address of the
  3138. NAT plus the LAN address(es) with the respective ports).
  3139. The solution is the following. If Alice wants to validate that a given
  3140. address for Bob is valid (i.e. is actually established @strong{directly}
  3141. with the intended target), she sends a PING message over that connection
  3142. to Bob. Note that in this case, Alice initiated the connection so only
  3143. Alice knows which address was used for sure (Alice may be behind NAT, so
  3144. whatever address Bob sees may not be an address Alice knows she has).
  3145. Bob checks that the address given in the @code{PING} is actually one
  3146. of Bob's addresses (ie: does not belong to Mallory), and if it is,
  3147. sends back a @code{PONG} (with a signature that says that Bob
  3148. owns/uses the address from the @code{PING}).
  3149. Alice checks the signature and is happy if it is valid and the address
  3150. in the @code{PONG} is the address Alice used.
  3151. This is similar to the 0.8.x protocol where the @code{HELLO} contained a
  3152. signature from Bob for each address used by Bob.
  3153. Here, the purpose code for the signature is
  3154. @code{GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN}. After this, Alice will
  3155. remember Bob's address and consider the address valid for a while (12h in
  3156. the current implementation). Note that after this exchange, Alice only
  3157. considers Bob's address to be valid, the connection itself is not
  3158. considered 'established'. In particular, Alice may have many addresses
  3159. for Bob that Alice considers valid.
  3160. The @code{PONG} message is protected with a nonce/challenge against replay
  3161. attacks (@uref{http://en.wikipedia.org/wiki/Replay_attack, replay})
  3162. and uses an expiration time for the signature (but those are almost
  3163. implementation details).
  3164. @cindex NAT library
  3165. @node NAT library
  3166. @section NAT library
  3167. The goal of the GNUnet NAT library is to provide a general-purpose API for
  3168. NAT traversal @strong{without} third-party support. So protocols that
  3169. involve contacting a third peer to help establish a connection between
  3170. two peers are outside of the scope of this API. That does not mean that
  3171. GNUnet doesn't support involving a third peer (we can do this with the
  3172. distance-vector transport or using application-level protocols), it just
  3173. means that the NAT API is not concerned with this possibility. The API is
  3174. written so that it will work for IPv6-NAT in the future as well as
  3175. current IPv4-NAT. Furthermore, the NAT API is always used, even for peers
  3176. that are not behind NAT --- in that case, the mapping provided is simply
  3177. the identity.
  3178. NAT traversal is initiated by calling @code{GNUNET_NAT_register}. Given a
  3179. set of addresses that the peer has locally bound to (TCP or UDP), the NAT
  3180. library will return (via callback) a (possibly longer) list of addresses
  3181. the peer @strong{might} be reachable under. Internally, depending on the
  3182. configuration, the NAT library will try to punch a hole (using UPnP) or
  3183. just "know" that the NAT was manually punched and generate the respective
  3184. external IP address (the one that should be globally visible) based on
  3185. the given information.
  3186. The NAT library also supports ICMP-based NAT traversal. Here, the other
  3187. peer can request connection-reversal by this peer (in this special case,
  3188. the peer is even allowed to configure a port number of zero). If the NAT
  3189. library detects a connection-reversal request, it returns the respective
  3190. target address to the client as well. It should be noted that
  3191. connection-reversal is currently only intended for TCP, so other plugins
  3192. @strong{must} pass @code{NULL} for the reversal callback. Naturally, the
  3193. NAT library also supports requesting connection reversal from a remote
  3194. peer (@code{GNUNET_NAT_run_client}).
  3195. Once initialized, the NAT handle can be used to test if a given address is
  3196. possibly a valid address for this peer (@code{GNUNET_NAT_test_address}).
  3197. This is used for validating our addresses when generating PONGs.
  3198. Finally, the NAT library contains an API to test if our NAT configuration
  3199. is correct. Using @code{GNUNET_NAT_test_start} @strong{before} binding to
  3200. the respective port, the NAT library can be used to test if the
  3201. configuration works. The test function act as a local client, initialize
  3202. the NAT traversal and then contact a @code{gnunet-nat-server} (running by
  3203. default on @code{gnunet.org}) and ask for a connection to be established.
  3204. This way, it is easy to test if the current NAT configuration is valid.
  3205. @node Distance-Vector plugin
  3206. @section Distance-Vector plugin
  3207. The Distance Vector (DV) transport is a transport mechanism that allows
  3208. peers to act as relays for each other, thereby connecting peers that would
  3209. otherwise be unable to connect. This gives a larger connection set to
  3210. applications that may work better with more peers to choose from (for
  3211. example, File Sharing and/or DHT).
  3212. The Distance Vector transport essentially has two functions. The first is
  3213. "gossiping" connection information about more distant peers to directly
  3214. connected peers. The second is taking messages intended for non-directly
  3215. connected peers and encapsulating them in a DV wrapper that contains the
  3216. required information for routing the message through forwarding peers. Via
  3217. gossiping, optimal routes through the known DV neighborhood are discovered
  3218. and utilized and the message encapsulation provides some benefits in
  3219. addition to simply getting the message from the correct source to the
  3220. proper destination.
  3221. The gossiping function of DV provides an up to date routing table of
  3222. peers that are available up to some number of hops. We call this a
  3223. fisheye view of the network (like a fish, nearby objects are known while
  3224. more distant ones unknown). Gossip messages are sent only to directly
  3225. connected peers, but they are sent about other knowns peers within the
  3226. "fisheye distance". Whenever two peers connect, they immediately gossip
  3227. to each other about their appropriate other neighbors. They also gossip
  3228. about the newly connected peer to previously
  3229. connected neighbors. In order to keep the routing tables up to date,
  3230. disconnect notifications are propagated as gossip as well (because
  3231. disconnects may not be sent/received, timeouts are also used remove
  3232. stagnant routing table entries).
  3233. Routing of messages via DV is straightforward. When the DV transport is
  3234. notified of a message destined for a non-direct neighbor, the appropriate
  3235. forwarding peer is selected, and the base message is encapsulated in a DV
  3236. message which contains information about the initial peer and the intended
  3237. recipient. At each forwarding hop, the initial peer is validated (the
  3238. forwarding peer ensures that it has the initial peer in its neighborhood,
  3239. otherwise the message is dropped). Next the base message is
  3240. re-encapsulated in a new DV message for the next hop in the forwarding
  3241. chain (or delivered to the current peer, if it has arrived at the
  3242. destination).
  3243. Assume a three peer network with peers Alice, Bob and Carol. Assume that
  3244. @example
  3245. Alice <-> Bob and Bob <-> Carol
  3246. @end example
  3247. @noindent
  3248. are direct (e.g. over TCP or UDP transports) connections, but that
  3249. Alice cannot directly connect to Carol.
  3250. This may be the case due to NAT or firewall restrictions, or perhaps
  3251. based on one of the peers respective configurations. If the Distance
  3252. Vector transport is enabled on all three peers, it will automatically
  3253. discover (from the gossip protocol) that Alice and Carol can connect via
  3254. Bob and provide a "virtual" Alice <-> Carol connection. Routing between
  3255. Alice and Carol happens as follows; Alice creates a message destined for
  3256. Carol and notifies the DV transport about it. The DV transport at Alice
  3257. looks up Carol in the routing table and finds that the message must be
  3258. sent through Bob for Carol. The message is encapsulated setting Alice as
  3259. the initiator and Carol as the destination and sent to Bob. Bob receives
  3260. the messages, verifies that both Alice and Carol are known to Bob, and
  3261. re-wraps the message in a new DV message for Carol.
  3262. The DV transport at Carol receives this message, unwraps the original
  3263. message, and delivers it to Carol as though it came directly from Alice.
  3264. @cindex SMTP plugin
  3265. @node SMTP plugin
  3266. @section SMTP plugin
  3267. @c TODO: Update!
  3268. This section describes the new SMTP transport plugin for GNUnet as it
  3269. exists in the 0.7.x and 0.8.x branch. SMTP support is currently not
  3270. available in GNUnet 0.9.x. This page also describes the transport layer
  3271. abstraction (as it existed in 0.7.x and 0.8.x) in more detail and gives
  3272. some benchmarking results. The performance results presented are quite
  3273. old and maybe outdated at this point.
  3274. For the readers in the year 2019, you will notice by the mention of
  3275. version 0.7, 0.8, and 0.9 that this section has to be taken with your
  3276. usual grain of salt and be updated eventually.
  3277. @itemize @bullet
  3278. @item Why use SMTP for a peer-to-peer transport?
  3279. @item SMTPHow does it work?
  3280. @item How do I configure my peer?
  3281. @item How do I test if it works?
  3282. @item How fast is it?
  3283. @item Is there any additional documentation?
  3284. @end itemize
  3285. @menu
  3286. * Why use SMTP for a peer-to-peer transport?::
  3287. * How does it work?::
  3288. * How do I configure my peer?::
  3289. * How do I test if it works?::
  3290. * How fast is it?::
  3291. @end menu
  3292. @node Why use SMTP for a peer-to-peer transport?
  3293. @subsection Why use SMTP for a peer-to-peer transport?
  3294. There are many reasons why one would not want to use SMTP:
  3295. @itemize @bullet
  3296. @item SMTP is using more bandwidth than TCP, UDP or HTTP
  3297. @item SMTP has a much higher latency.
  3298. @item SMTP requires significantly more computation (encoding and decoding
  3299. time) for the peers.
  3300. @item SMTP is significantly more complicated to configure.
  3301. @item SMTP may be abused by tricking GNUnet into sending mail to@
  3302. non-participating third parties.
  3303. @end itemize
  3304. So why would anybody want to use SMTP?
  3305. @itemize @bullet
  3306. @item SMTP can be used to contact peers behind NAT boxes (in virtual
  3307. private networks).
  3308. @item SMTP can be used to circumvent policies that limit or prohibit
  3309. peer-to-peer traffic by masking as "legitimate" traffic.
  3310. @item SMTP uses E-mail addresses which are independent of a specific IP,
  3311. which can be useful to address peers that use dynamic IP addresses.
  3312. @item SMTP can be used to initiate a connection (e.g. initial address
  3313. exchange) and peers can then negotiate the use of a more efficient
  3314. protocol (e.g. TCP) for the actual communication.
  3315. @end itemize
  3316. In summary, SMTP can for example be used to send a message to a peer
  3317. behind a NAT box that has a dynamic IP to tell the peer to establish a
  3318. TCP connection to a peer outside of the private network. Even an
  3319. extraordinary overhead for this first message would be irrelevant in this
  3320. type of situation.
  3321. @node How does it work?
  3322. @subsection How does it work?
  3323. When a GNUnet peer needs to send a message to another GNUnet peer that has
  3324. advertised (only) an SMTP transport address, GNUnet base64-encodes the
  3325. message and sends it in an E-mail to the advertised address. The
  3326. advertisement contains a filter which is placed in the E-mail header,
  3327. such that the receiving host can filter the tagged E-mails and forward it
  3328. to the GNUnet peer process. The filter can be specified individually by
  3329. each peer and be changed over time. This makes it impossible to censor
  3330. GNUnet E-mail messages by searching for a generic filter.
  3331. @node How do I configure my peer?
  3332. @subsection How do I configure my peer?
  3333. First, you need to configure @code{procmail} to filter your inbound E-mail
  3334. for GNUnet traffic. The GNUnet messages must be delivered into a pipe, for
  3335. example @code{/tmp/gnunet.smtp}. You also need to define a filter that is
  3336. used by @command{procmail} to detect GNUnet messages. You are free to
  3337. choose whichever filter you like, but you should make sure that it does
  3338. not occur in your other E-mail. In our example, we will use
  3339. @code{X-mailer: GNUnet}. The @code{~/.procmailrc} configuration file then
  3340. looks like this:
  3341. @example
  3342. :0:
  3343. * ^X-mailer: GNUnet
  3344. /tmp/gnunet.smtp
  3345. # where do you want your other e-mail delivered to
  3346. # (default: /var/spool/mail/)
  3347. :0: /var/spool/mail/
  3348. @end example
  3349. After adding this file, first make sure that your regular E-mail still
  3350. works (e.g. by sending an E-mail to yourself). Then edit the GNUnet
  3351. configuration. In the section @code{SMTP} you need to specify your E-mail
  3352. address under @code{EMAIL}, your mail server (for outgoing mail) under
  3353. @code{SERVER}, the filter (X-mailer: GNUnet in the example) under
  3354. @code{FILTER} and the name of the pipe under @code{PIPE}.@ The completed
  3355. section could then look like this:
  3356. @example
  3357. EMAIL = me@@mail.gnu.org MTU = 65000 SERVER = mail.gnu.org:25 FILTER =
  3358. "X-mailer: GNUnet" PIPE = /tmp/gnunet.smtp
  3359. @end example
  3360. Finally, you need to add @code{smtp} to the list of @code{TRANSPORTS} in
  3361. the @code{GNUNETD} section. GNUnet peers will use the E-mail address that
  3362. you specified to contact your peer until the advertisement times out.
  3363. Thus, if you are not sure if everything works properly or if you are not
  3364. planning to be online for a long time, you may want to configure this
  3365. timeout to be short, e.g. just one hour. For this, set
  3366. @code{HELLOEXPIRES} to @code{1} in the @code{GNUNETD} section.
  3367. This should be it, but you may probably want to test it first.
  3368. @node How do I test if it works?
  3369. @subsection How do I test if it works?
  3370. Any transport can be subjected to some rudimentary tests using the
  3371. @code{gnunet-transport-check} tool. The tool sends a message to the local
  3372. node via the transport and checks that a valid message is received. While
  3373. this test does not involve other peers and can not check if firewalls or
  3374. other network obstacles prohibit proper operation, this is a great
  3375. testcase for the SMTP transport since it tests pretty much nearly all of
  3376. the functionality.
  3377. @code{gnunet-transport-check} should only be used without running
  3378. @code{gnunetd} at the same time. By default, @code{gnunet-transport-check}
  3379. tests all transports that are specified in the configuration file. But
  3380. you can specifically test SMTP by giving the option
  3381. @code{--transport=smtp}.
  3382. Note that this test always checks if a transport can receive and send.
  3383. While you can configure most transports to only receive or only send
  3384. messages, this test will only work if you have configured the transport
  3385. to send and receive messages.
  3386. @node How fast is it?
  3387. @subsection How fast is it?
  3388. We have measured the performance of the UDP, TCP and SMTP transport layer
  3389. directly and when used from an application using the GNUnet core.
  3390. Measuring just the transport layer gives the better view of the actual
  3391. overhead of the protocol, whereas evaluating the transport from the
  3392. application puts the overhead into perspective from a practical point of
  3393. view.
  3394. The loopback measurements of the SMTP transport were performed on three
  3395. different machines spanning a range of modern SMTP configurations. We
  3396. used a PIII-800 running RedHat 7.3 with the Purdue Computer Science
  3397. configuration which includes filters for spam. We also used a Xenon 2 GHZ
  3398. with a vanilla RedHat 8.0 sendmail configuration. Furthermore, we used
  3399. qmail on a PIII-1000 running Sorcerer GNU Linux (SGL). The numbers for
  3400. UDP and TCP are provided using the SGL configuration. The qmail benchmark
  3401. uses qmail's internal filtering whereas the sendmail benchmarks relies on
  3402. procmail to filter and deliver the mail. We used the transport layer to
  3403. send a message of b bytes (excluding transport protocol headers) directly
  3404. to the local machine. This way, network latency and packet loss on the
  3405. wire have no impact on the timings. n messages were sent sequentially over
  3406. the transport layer, sending message i+1 after the i-th message was
  3407. received. All messages were sent over the same connection and the time to
  3408. establish the connection was not taken into account since this overhead is
  3409. minuscule in practice --- as long as a connection is used for a
  3410. significant number of messages.
  3411. @multitable @columnfractions .20 .15 .15 .15 .15 .15
  3412. @headitem Transport @tab UDP @tab TCP @tab SMTP (Purdue sendmail)
  3413. @tab SMTP (RH 8.0) @tab SMTP (SGL qmail)
  3414. @item 11 bytes @tab 31 ms @tab 55 ms @tab 781 s @tab 77 s @tab 24 s
  3415. @item 407 bytes @tab 37 ms @tab 62 ms @tab 789 s @tab 78 s @tab 25 s
  3416. @item 1,221 bytes @tab 46 ms @tab 73 ms @tab 804 s @tab 78 s @tab 25 s
  3417. @end multitable
  3418. The benchmarks show that UDP and TCP are, as expected, both significantly
  3419. faster compared with any of the SMTP services. Among the SMTP
  3420. implementations, there can be significant differences depending on the
  3421. SMTP configuration. Filtering with an external tool like procmail that
  3422. needs to re-parse its configuration for each mail can be very expensive.
  3423. Applying spam filters can also significantly impact the performance of
  3424. the underlying SMTP implementation. The microbenchmark shows that SMTP
  3425. can be a viable solution for initiating peer-to-peer sessions: a couple of
  3426. seconds to connect to a peer are probably not even going to be noticed by
  3427. users. The next benchmark measures the possible throughput for a
  3428. transport. Throughput can be measured by sending multiple messages in
  3429. parallel and measuring packet loss. Note that not only UDP but also the
  3430. TCP transport can actually loose messages since the TCP implementation
  3431. drops messages if the @code{write} to the socket would block. While the
  3432. SMTP protocol never drops messages itself, it is often so
  3433. slow that only a fraction of the messages can be sent and received in the
  3434. given time-bounds. For this benchmark we report the message loss after
  3435. allowing t time for sending m messages. If messages were not sent (or
  3436. received) after an overall timeout of t, they were considered lost. The
  3437. benchmark was performed using two Xeon 2 GHZ machines running RedHat 8.0
  3438. with sendmail. The machines were connected with a direct 100 MBit Ethernet
  3439. connection.@ Figures udp1200, tcp1200 and smtp-MTUs show that the
  3440. throughput for messages of size 1,200 octets is 2,343 kbps, 3,310 kbps
  3441. and 6 kbps for UDP, TCP and SMTP respectively. The high per-message
  3442. overhead of SMTP can be improved by increasing the MTU, for example, an
  3443. MTU of 12,000 octets improves the throughput to 13 kbps as figure
  3444. smtp-MTUs shows. Our research paper) has some more details on the
  3445. benchmarking results.
  3446. @cindex Bluetooth plugin
  3447. @node Bluetooth plugin
  3448. @section Bluetooth plugin
  3449. This page describes the new Bluetooth transport plugin for GNUnet. The
  3450. plugin is still in the testing stage so don't expect it to work
  3451. perfectly. If you have any questions or problems just post them here or
  3452. ask on the IRC channel.
  3453. @itemize @bullet
  3454. @item What do I need to use the Bluetooth plugin transport?
  3455. @item BluetoothHow does it work?
  3456. @item What possible errors should I be aware of?
  3457. @item How do I configure my peer?
  3458. @item How can I test it?
  3459. @end itemize
  3460. @menu
  3461. * What do I need to use the Bluetooth plugin transport?::
  3462. * How does it work2?::
  3463. * What possible errors should I be aware of?::
  3464. * How do I configure my peer2?::
  3465. * How can I test it?::
  3466. * The implementation of the Bluetooth transport plugin::
  3467. @end menu
  3468. @node What do I need to use the Bluetooth plugin transport?
  3469. @subsection What do I need to use the Bluetooth plugin transport?
  3470. If you are a GNU/Linux user and you want to use the Bluetooth
  3471. transport plugin you should install the
  3472. @command{BlueZ} development libraries (if they aren't already
  3473. installed).
  3474. For instructions about how to install the libraries you should
  3475. check out the BlueZ site
  3476. (@uref{http://www.bluez.org/, http://www.bluez.org}). If you don't know if
  3477. you have the necessary libraries, don't worry, just run the GNUnet
  3478. configure script and you will be able to see a notification at the end
  3479. which will warn you if you don't have the necessary libraries.
  3480. @c If you are a Windows user you should have installed the
  3481. @c @emph{MinGW}/@emph{MSys2} with the latest updates (especially the
  3482. @c @emph{ws2bth} header). If this is your first build of GNUnet on Windows
  3483. @c you should check out the SBuild repository. It will semi-automatically
  3484. @c assembles a @emph{MinGW}/@emph{MSys2} installation with a lot of extra
  3485. @c packages which are needed for the GNUnet build. So this will ease your
  3486. @c work!@ Finally you just have to be sure that you have the correct drivers
  3487. @c for your Bluetooth device installed and that your device is on and in a
  3488. @c discoverable mode. The Windows Bluetooth Stack supports only the RFCOMM
  3489. @c protocol so we cannot turn on your device programatically!
  3490. @c FIXME: Change to unique title
  3491. @node How does it work2?
  3492. @subsection How does it work2?
  3493. The Bluetooth transport plugin uses virtually the same code as the WLAN
  3494. plugin and only the helper binary is different. The helper takes a single
  3495. argument, which represents the interface name and is specified in the
  3496. configuration file. Here are the basic steps that are followed by the
  3497. helper binary used on GNU/Linux:
  3498. @itemize @bullet
  3499. @item it verifies if the name corresponds to a Bluetooth interface name
  3500. @item it verifies if the interface is up (if it is not, it tries to bring
  3501. it up)
  3502. @item it tries to enable the page and inquiry scan in order to make the
  3503. device discoverable and to accept incoming connection requests
  3504. @emph{The above operations require root access so you should start the
  3505. transport plugin with root privileges.}
  3506. @item it finds an available port number and registers a SDP service which
  3507. will be used to find out on which port number is the server listening on
  3508. and switch the socket in listening mode
  3509. @item it sends a HELLO message with its address
  3510. @item finally it forwards traffic from the reading sockets to the STDOUT
  3511. and from the STDIN to the writing socket
  3512. @end itemize
  3513. Once in a while the device will make an inquiry scan to discover the
  3514. nearby devices and it will send them randomly HELLO messages for peer
  3515. discovery.
  3516. @node What possible errors should I be aware of?
  3517. @subsection What possible errors should I be aware of?
  3518. @emph{This section is dedicated for GNU/Linux users}
  3519. Well there are many ways in which things could go wrong but I will try to
  3520. present some tools that you could use to debug and some scenarios.
  3521. @itemize @bullet
  3522. @item @code{bluetoothd -n -d} : use this command to enable logging in the
  3523. foreground and to print the logging messages
  3524. @item @code{hciconfig}: can be used to configure the Bluetooth devices.
  3525. If you run it without any arguments it will print information about the
  3526. state of the interfaces. So if you receive an error that the device
  3527. couldn't be brought up you should try to bring it manually and to see if
  3528. it works (use @code{hciconfig -a hciX up}). If you can't and the
  3529. Bluetooth address has the form 00:00:00:00:00:00 it means that there is
  3530. something wrong with the D-Bus daemon or with the Bluetooth daemon. Use
  3531. @code{bluetoothd} tool to see the logs
  3532. @item @code{sdptool} can be used to control and interrogate SDP servers.
  3533. If you encounter problems regarding the SDP server (like the SDP server is
  3534. down) you should check out if the D-Bus daemon is running correctly and to
  3535. see if the Bluetooth daemon started correctly(use @code{bluetoothd} tool).
  3536. Also, sometimes the SDP service could work but somehow the device couldn't
  3537. register its service. Use @code{sdptool browse [dev-address]} to see if
  3538. the service is registered. There should be a service with the name of the
  3539. interface and GNUnet as provider.
  3540. @item @code{hcitool} : another useful tool which can be used to configure
  3541. the device and to send some particular commands to it.
  3542. @item @code{hcidump} : could be used for low level debugging
  3543. @end itemize
  3544. @c FIXME: A more unique name
  3545. @node How do I configure my peer2?
  3546. @subsection How do I configure my peer2?
  3547. On GNU/Linux, you just have to be sure that the interface name
  3548. corresponds to the one that you want to use.
  3549. Use the @code{hciconfig} tool to check that.
  3550. By default it is set to hci0 but you can change it.
  3551. A basic configuration looks like this:
  3552. @example
  3553. [transport-bluetooth]
  3554. # Name of the interface (typically hciX)
  3555. INTERFACE = hci0
  3556. # Real hardware, no testing
  3557. TESTMODE = 0 TESTING_IGNORE_KEYS = ACCEPT_FROM;
  3558. @end example
  3559. In order to use the Bluetooth transport plugin when the transport service
  3560. is started, you must add the plugin name to the default transport service
  3561. plugins list. For example:
  3562. @example
  3563. [transport] ... PLUGINS = dns bluetooth ...
  3564. @end example
  3565. If you want to use only the Bluetooth plugin set
  3566. @emph{PLUGINS = bluetooth}
  3567. On Windows, you cannot specify which device to use. The only thing that
  3568. you should do is to add @emph{bluetooth} on the plugins list of the
  3569. transport service.
  3570. @node How can I test it?
  3571. @subsection How can I test it?
  3572. If you have two Bluetooth devices on the same machine and you are using
  3573. GNU/Linux you must:
  3574. @itemize @bullet
  3575. @item create two different file configuration (one which will use the
  3576. first interface (@emph{hci0}) and the other which will use the second
  3577. interface (@emph{hci1})). Let's name them @emph{peer1.conf} and
  3578. @emph{peer2.conf}.
  3579. @item run @emph{gnunet-peerinfo -c peerX.conf -s} in order to generate the
  3580. peers private keys. The @strong{X} must be replace with 1 or 2.
  3581. @item run @emph{gnunet-arm -c peerX.conf -s -i=transport} in order to
  3582. start the transport service. (Make sure that you have "bluetooth" on the
  3583. transport plugins list if the Bluetooth transport service doesn't start.)
  3584. @item run @emph{gnunet-peerinfo -c peer1.conf -s} to get the first peer's
  3585. ID. If you already know your peer ID (you saved it from the first
  3586. command), this can be skipped.
  3587. @item run @emph{gnunet-transport -c peer2.conf -p=PEER1_ID -s} to start
  3588. sending data for benchmarking to the other peer.
  3589. @end itemize
  3590. This scenario will try to connect the second peer to the first one and
  3591. then start sending data for benchmarking.
  3592. @c On Windows you cannot test the plugin functionality using two Bluetooth
  3593. @c devices from the same machine because after you install the drivers there
  3594. @c will occur some conflicts between the Bluetooth stacks. (At least that is
  3595. @c what happened on my machine : I wasn't able to use the Bluesoleil stack and
  3596. @c the WINDCOMM one in the same time).
  3597. If you have two different machines and your configuration files are good
  3598. you can use the same scenario presented on the beginning of this section.
  3599. Another way to test the plugin functionality is to create your own
  3600. application which will use the GNUnet framework with the Bluetooth
  3601. transport service.
  3602. @node The implementation of the Bluetooth transport plugin
  3603. @subsection The implementation of the Bluetooth transport plugin
  3604. This page describes the implementation of the Bluetooth transport plugin.
  3605. First I want to remind you that the Bluetooth transport plugin uses
  3606. virtually the same code as the WLAN plugin and only the helper binary is
  3607. different. Also the scope of the helper binary from the Bluetooth
  3608. transport plugin is the same as the one used for the WLAN transport
  3609. plugin: it accesses the interface and then it forwards traffic in both
  3610. directions between the Bluetooth interface and stdin/stdout of the
  3611. process involved.
  3612. The Bluetooth plugin transport could be used both on GNU/Linux and Windows
  3613. platforms.
  3614. @itemize @bullet
  3615. @item Linux functionality
  3616. @c @item Windows functionality
  3617. @item Pending Features
  3618. @end itemize
  3619. @menu
  3620. * Linux functionality::
  3621. * THE INITIALIZATION::
  3622. * THE LOOP::
  3623. * Details about the broadcast implementation::
  3624. @c * Windows functionality::
  3625. * Pending features::
  3626. @end menu
  3627. @node Linux functionality
  3628. @subsubsection Linux functionality
  3629. In order to implement the plugin functionality on GNU/Linux I
  3630. used the BlueZ stack.
  3631. For the communication with the other devices I used the RFCOMM
  3632. protocol. Also I used the HCI protocol to gain some control over the
  3633. device. The helper binary takes a single argument (the name of the
  3634. Bluetooth interface) and is separated in two stages:
  3635. @c %** 'THE INITIALIZATION' should be in bigger letters or stand out, not
  3636. @c %** starting a new section?
  3637. @node THE INITIALIZATION
  3638. @subsubsection THE INITIALIZATION
  3639. @itemize @bullet
  3640. @item first, it checks if we have root privileges
  3641. (@emph{Remember that we need to have root privileges in order to be able
  3642. to bring the interface up if it is down or to change its state.}).
  3643. @item second, it verifies if the interface with the given name exists.
  3644. @strong{If the interface with that name exists and it is a Bluetooth
  3645. interface:}
  3646. @item it creates a RFCOMM socket which will be used for listening and call
  3647. the @emph{open_device} method
  3648. On the @emph{open_device} method:
  3649. @itemize @bullet
  3650. @item creates a HCI socket used to send control events to the device
  3651. @item searches for the device ID using the interface name
  3652. @item saves the device MAC address
  3653. @item checks if the interface is down and tries to bring it UP
  3654. @item checks if the interface is in discoverable mode and tries to make it
  3655. discoverable
  3656. @item closes the HCI socket and binds the RFCOMM one
  3657. @item switches the RFCOMM socket in listening mode
  3658. @item registers the SDP service (the service will be used by the other
  3659. devices to get the port on which this device is listening on)
  3660. @end itemize
  3661. @item drops the root privileges
  3662. @strong{If the interface is not a Bluetooth interface the helper exits
  3663. with a suitable error}
  3664. @end itemize
  3665. @c %** Same as for @node entry above
  3666. @node THE LOOP
  3667. @subsubsection THE LOOP
  3668. The helper binary uses a list where it saves all the connected neighbour
  3669. devices (@emph{neighbours.devices}) and two buffers (@emph{write_pout} and
  3670. @emph{write_std}). The first message which is send is a control message
  3671. with the device's MAC address in order to announce the peer presence to
  3672. the neighbours. Here are a short description of what happens in the main
  3673. loop:
  3674. @itemize @bullet
  3675. @item Every time when it receives something from the STDIN it processes
  3676. the data and saves the message in the first buffer (@emph{write_pout}).
  3677. When it has something in the buffer, it gets the destination address from
  3678. the buffer, searches the destination address in the list (if there is no
  3679. connection with that device, it creates a new one and saves it to the
  3680. list) and sends the message.
  3681. @item Every time when it receives something on the listening socket it
  3682. accepts the connection and saves the socket on a list with the reading
  3683. sockets. @item Every time when it receives something from a reading
  3684. socket it parses the message, verifies the CRC and saves it in the
  3685. @emph{write_std} buffer in order to be sent later to the STDOUT.
  3686. @end itemize
  3687. So in the main loop we use the select function to wait until one of the
  3688. file descriptor saved in one of the two file descriptors sets used is
  3689. ready to use. The first set (@emph{rfds}) represents the reading set and
  3690. it could contain the list with the reading sockets, the STDIN file
  3691. descriptor or the listening socket. The second set (@emph{wfds}) is the
  3692. writing set and it could contain the sending socket or the STDOUT file
  3693. descriptor. After the select function returns, we check which file
  3694. descriptor is ready to use and we do what is supposed to do on that kind
  3695. of event. @emph{For example:} if it is the listening socket then we
  3696. accept a new connection and save the socket in the reading list; if it is
  3697. the STDOUT file descriptor, then we write to STDOUT the message from the
  3698. @emph{write_std} buffer.
  3699. To find out on which port a device is listening on we connect to the local
  3700. SDP server and search the registered service for that device.
  3701. @emph{You should be aware of the fact that if the device fails to connect
  3702. to another one when trying to send a message it will attempt one more
  3703. time. If it fails again, then it skips the message.}
  3704. @emph{Also you should know that the transport Bluetooth plugin has
  3705. support for @strong{broadcast messages}.}
  3706. @node Details about the broadcast implementation
  3707. @subsubsection Details about the broadcast implementation
  3708. First I want to point out that the broadcast functionality for the CONTROL
  3709. messages is not implemented in a conventional way. Since the inquiry scan
  3710. time is too big and it will take some time to send a message to all the
  3711. discoverable devices I decided to tackle the problem in a different way.
  3712. Here is how I did it:
  3713. @itemize @bullet
  3714. @item If it is the first time when I have to broadcast a message I make an
  3715. inquiry scan and save all the devices' addresses to a vector.
  3716. @item After the inquiry scan ends I take the first address from the list
  3717. and I try to connect to it. If it fails, I try to connect to the next one.
  3718. If it succeeds, I save the socket to a list and send the message to the
  3719. device.
  3720. @item When I have to broadcast another message, first I search on the list
  3721. for a new device which I'm not connected to. If there is no new device on
  3722. the list I go to the beginning of the list and send the message to the
  3723. old devices. After 5 cycles I make a new inquiry scan to check out if
  3724. there are new discoverable devices and save them to the list. If there
  3725. are no new discoverable devices I reset the cycling counter and go again
  3726. through the old list and send messages to the devices saved in it.
  3727. @end itemize
  3728. @strong{Therefore}:
  3729. @itemize @bullet
  3730. @item every time when I have a broadcast message I look up on the list
  3731. for a new device and send the message to it
  3732. @item if I reached the end of the list for 5 times and I'm connected to
  3733. all the devices from the list I make a new inquiry scan.
  3734. @emph{The number of the list's cycles after an inquiry scan could be
  3735. increased by redefining the MAX_LOOPS variable}
  3736. @item when there are no new devices I send messages to the old ones.
  3737. @end itemize
  3738. Doing so, the broadcast control messages will reach the devices but with
  3739. delay.
  3740. @emph{NOTICE:} When I have to send a message to a certain device first I
  3741. check on the broadcast list to see if we are connected to that device. If
  3742. not we try to connect to it and in case of success we save the address and
  3743. the socket on the list. If we are already connected to that device we
  3744. simply use the socket.
  3745. @c @node Windows functionality
  3746. @c @subsubsection Windows functionality
  3747. @c For Windows I decided to use the Microsoft Bluetooth stack which has the
  3748. @c advantage of coming standard from Windows XP SP2. The main disadvantage is
  3749. @c that it only supports the RFCOMM protocol so we will not be able to have
  3750. @c a low level control over the Bluetooth device. Therefore it is the user
  3751. @c responsibility to check if the device is up and in the discoverable mode.
  3752. @c Also there are no tools which could be used for debugging in order to read
  3753. @c the data coming from and going to a Bluetooth device, which obviously
  3754. @c hindered my work. Another thing that slowed down the implementation of the
  3755. @c plugin (besides that I wasn't too accommodated with the win32 API) was that
  3756. @c there were some bugs on MinGW regarding the Bluetooth. Now they are solved
  3757. @c but you should keep in mind that you should have the latest updates
  3758. @c (especially the @emph{ws2bth} header).
  3759. @c Besides the fact that it uses the Windows Sockets, the Windows
  3760. @c implementation follows the same principles as the GNU/Linux one:
  3761. @c @itemize @bullet
  3762. @c @item It has a initalization part where it initializes the
  3763. @c Windows Sockets, creates a RFCOMM socket which will be binded and switched
  3764. @c to the listening mode and registers a SDP service. In the Microsoft
  3765. @c Bluetooth API there are two ways to work with the SDP:
  3766. @c @itemize @bullet
  3767. @c @item an easy way which works with very simple service records
  3768. @c @item a hard way which is useful when you need to update or to delete the
  3769. @c record
  3770. @c @end itemize
  3771. @c @end itemize
  3772. @c Since I only needed the SDP service to find out on which port the device
  3773. @c is listening on and that did not change, I decided to use the easy way.
  3774. @c In order to register the service I used the @emph{WSASetService} function
  3775. @c and I generated the @emph{Universally Unique Identifier} with the
  3776. @c @emph{guidgen.exe} Windows's tool.
  3777. @c In the loop section the only difference from the GNU/Linux implementation
  3778. @c is that I used the @code{GNUNET_NETWORK} library for
  3779. @c functions like @emph{accept}, @emph{bind}, @emph{connect} or
  3780. @c @emph{select}. I decided to use the
  3781. @c @code{GNUNET_NETWORK} library because I also needed to interact
  3782. @c with the STDIN and STDOUT handles and on Windows
  3783. @c the select function is only defined for sockets,
  3784. @c and it will not work for arbitrary file handles.
  3785. @c Another difference between GNU/Linux and Windows implementation is that in
  3786. @c GNU/Linux, the Bluetooth address is represented in 48 bits
  3787. @c while in Windows is represented in 64 bits.
  3788. @c Therefore I had to do some changes on @emph{plugin_transport_wlan} header.
  3789. @c Also, currently on Windows the Bluetooth plugin doesn't have support for
  3790. @c broadcast messages. When it receives a broadcast message it will skip it.
  3791. @node Pending features
  3792. @subsubsection Pending features
  3793. @itemize @bullet
  3794. @c @item Implement the broadcast functionality on Windows @emph{(currently
  3795. @c working on)}
  3796. @item Implement a testcase for the helper :@ @emph{The testcase
  3797. consists of a program which emulates the plugin and uses the helper. It
  3798. will simulate connections, disconnections and data transfers.}
  3799. @end itemize
  3800. If you have a new idea about a feature of the plugin or suggestions about
  3801. how I could improve the implementation you are welcome to comment or to
  3802. contact me.
  3803. @node WLAN plugin
  3804. @section WLAN plugin
  3805. This section documents how the wlan transport plugin works. Parts which
  3806. are not implemented yet or could be better implemented are described at
  3807. the end.
  3808. @cindex ATS Subsystem
  3809. @node ATS Subsystem
  3810. @section ATS Subsystem
  3811. ATS stands for "automatic transport selection", and the function of ATS in
  3812. GNUnet is to decide on which address (and thus transport plugin) should
  3813. be used for two peers to communicate, and what bandwidth limits should be
  3814. imposed on such an individual connection. To help ATS make an informed
  3815. decision, higher-level services inform the ATS service about their
  3816. requirements and the quality of the service rendered. The ATS service
  3817. also interacts with the transport service to be appraised of working
  3818. addresses and to communicate its resource allocation decisions. Finally,
  3819. the ATS service's operation can be observed using a monitoring API.
  3820. The main logic of the ATS service only collects the available addresses,
  3821. their performance characteristics and the applications requirements, but
  3822. does not make the actual allocation decision. This last critical step is
  3823. left to an ATS plugin, as we have implemented (currently three) different
  3824. allocation strategies which differ significantly in their performance and
  3825. maturity, and it is still unclear if any particular plugin is generally
  3826. superior.
  3827. @cindex CORE Subsystem
  3828. @node CORE Subsystem
  3829. @section CORE Subsystem
  3830. The CORE subsystem in GNUnet is responsible for securing link-layer
  3831. communications between nodes in the GNUnet overlay network. CORE builds
  3832. on the TRANSPORT subsystem which provides for the actual, insecure,
  3833. unreliable link-layer communication (for example, via UDP or WLAN), and
  3834. then adds fundamental security to the connections:
  3835. @itemize @bullet
  3836. @item confidentiality with so-called perfect forward secrecy; we use
  3837. ECDHE
  3838. (@uref{http://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman, Elliptic-curve Diffie---Hellman})
  3839. powered by Curve25519
  3840. (@uref{http://cr.yp.to/ecdh.html, Curve25519}) for the key
  3841. exchange and then use symmetric encryption, encrypting with both AES-256
  3842. (@uref{http://en.wikipedia.org/wiki/Rijndael, AES-256}) and
  3843. Twofish (@uref{http://en.wikipedia.org/wiki/Twofish, Twofish})
  3844. @item @uref{http://en.wikipedia.org/wiki/Authentication, authentication}
  3845. is achieved by signing the ephemeral keys using Ed25519
  3846. (@uref{http://ed25519.cr.yp.to/, Ed25519}), a deterministic
  3847. variant of ECDSA
  3848. (@uref{http://en.wikipedia.org/wiki/ECDSA, ECDSA})
  3849. @item integrity protection (using SHA-512
  3850. (@uref{http://en.wikipedia.org/wiki/SHA-2, SHA-512}) to do
  3851. encrypt-then-MAC
  3852. (@uref{http://en.wikipedia.org/wiki/Authenticated_encryption, encrypt-then-MAC}))
  3853. @item Replay
  3854. (@uref{http://en.wikipedia.org/wiki/Replay_attack, replay})
  3855. protection (using nonces, timestamps, challenge-response,
  3856. message counters and ephemeral keys)
  3857. @item liveness (keep-alive messages, timeout)
  3858. @end itemize
  3859. @menu
  3860. * Limitations::
  3861. * When is a peer "connected"?::
  3862. * libgnunetcore::
  3863. * The CORE Client-Service Protocol::
  3864. * The CORE Peer-to-Peer Protocol::
  3865. @end menu
  3866. @cindex core subsystem limitations
  3867. @node Limitations
  3868. @subsection Limitations
  3869. CORE does not perform
  3870. @uref{http://en.wikipedia.org/wiki/Routing, routing}; using CORE it is
  3871. only possible to communicate with peers that happen to already be
  3872. "directly" connected with each other. CORE also does not have an
  3873. API to allow applications to establish such "direct" connections --- for
  3874. this, applications can ask TRANSPORT, but TRANSPORT might not be able to
  3875. establish a "direct" connection. The TOPOLOGY subsystem is responsible for
  3876. trying to keep a few "direct" connections open at all times. Applications
  3877. that need to talk to particular peers should use the CADET subsystem, as
  3878. it can establish arbitrary "indirect" connections.
  3879. Because CORE does not perform routing, CORE must only be used directly by
  3880. applications that either perform their own routing logic (such as
  3881. anonymous file-sharing) or that do not require routing, for example
  3882. because they are based on flooding the network. CORE communication is
  3883. unreliable and delivery is possibly out-of-order. Applications that
  3884. require reliable communication should use the CADET service. Each
  3885. application can only queue one message per target peer with the CORE
  3886. service at any time; messages cannot be larger than approximately
  3887. 63 kilobytes. If messages are small, CORE may group multiple messages
  3888. (possibly from different applications) prior to encryption. If permitted
  3889. by the application (using the @uref{http://baus.net/on-tcp_cork/, cork}
  3890. option), CORE may delay transmissions to facilitate grouping of multiple
  3891. small messages. If cork is not enabled, CORE will transmit the message as
  3892. soon as TRANSPORT allows it (TRANSPORT is responsible for limiting
  3893. bandwidth and congestion control). CORE does not allow flow control;
  3894. applications are expected to process messages at line-speed. If flow
  3895. control is needed, applications should use the CADET service.
  3896. @cindex when is a peer connected
  3897. @node When is a peer "connected"?
  3898. @subsection When is a peer "connected"?
  3899. In addition to the security features mentioned above, CORE also provides
  3900. one additional key feature to applications using it, and that is a
  3901. limited form of protocol-compatibility checking. CORE distinguishes
  3902. between TRANSPORT-level connections (which enable communication with other
  3903. peers) and application-level connections. Applications using the CORE API
  3904. will (typically) learn about application-level connections from CORE, and
  3905. not about TRANSPORT-level connections. When a typical application uses
  3906. CORE, it will specify a set of message types
  3907. (from @code{gnunet_protocols.h}) that it understands. CORE will then
  3908. notify the application about connections it has with other peers if and
  3909. only if those applications registered an intersecting set of message
  3910. types with their CORE service. Thus, it is quite possible that CORE only
  3911. exposes a subset of the established direct connections to a particular
  3912. application --- and different applications running above CORE might see
  3913. different sets of connections at the same time.
  3914. A special case are applications that do not register a handler for any
  3915. message type.
  3916. CORE assumes that these applications merely want to monitor connections
  3917. (or "all" messages via other callbacks) and will notify those applications
  3918. about all connections. This is used, for example, by the
  3919. @code{gnunet-core} command-line tool to display the active connections.
  3920. Note that it is also possible that the TRANSPORT service has more active
  3921. connections than the CORE service, as the CORE service first has to
  3922. perform a key exchange with connecting peers before exchanging information
  3923. about supported message types and notifying applications about the new
  3924. connection.
  3925. @cindex libgnunetcore
  3926. @node libgnunetcore
  3927. @subsection libgnunetcore
  3928. The CORE API (defined in @file{gnunet_core_service.h}) is the basic
  3929. messaging API used by P2P applications built using GNUnet. It provides
  3930. applications the ability to send and receive encrypted messages to the
  3931. peer's "directly" connected neighbours.
  3932. As CORE connections are generally "direct" connections,@ applications must
  3933. not assume that they can connect to arbitrary peers this way, as "direct"
  3934. connections may not always be possible. Applications using CORE are
  3935. notified about which peers are connected. Creating new "direct"
  3936. connections must be done using the TRANSPORT API.
  3937. The CORE API provides unreliable, out-of-order delivery. While the
  3938. implementation tries to ensure timely, in-order delivery, both message
  3939. losses and reordering are not detected and must be tolerated by the
  3940. application. Most important, the core will NOT perform retransmission if
  3941. messages could not be delivered.
  3942. Note that CORE allows applications to queue one message per connected
  3943. peer. The rate at which each connection operates is influenced by the
  3944. preferences expressed by local application as well as restrictions
  3945. imposed by the other peer. Local applications can express their
  3946. preferences for particular connections using the "performance" API of the
  3947. ATS service.
  3948. Applications that require more sophisticated transmission capabilities
  3949. such as TCP-like behavior, or if you intend to send messages to arbitrary
  3950. remote peers, should use the CADET API.
  3951. The typical use of the CORE API is to connect to the CORE service using
  3952. @code{GNUNET_CORE_connect}, process events from the CORE service (such as
  3953. peers connecting, peers disconnecting and incoming messages) and send
  3954. messages to connected peers using
  3955. @code{GNUNET_CORE_notify_transmit_ready}. Note that applications must
  3956. cancel pending transmission requests if they receive a disconnect event
  3957. for a peer that had a transmission pending; furthermore, queuing more
  3958. than one transmission request per peer per application using the
  3959. service is not permitted.
  3960. The CORE API also allows applications to monitor all communications of the
  3961. peer prior to encryption (for outgoing messages) or after decryption (for
  3962. incoming messages). This can be useful for debugging, diagnostics or to
  3963. establish the presence of cover traffic (for anonymity). As monitoring
  3964. applications are often not interested in the payload, the monitoring
  3965. callbacks can be configured to only provide the message headers (including
  3966. the message type and size) instead of copying the full data stream to the
  3967. monitoring client.
  3968. The init callback of the @code{GNUNET_CORE_connect} function is called
  3969. with the hash of the public key of the peer. This public key is used to
  3970. identify the peer globally in the GNUnet network. Applications are
  3971. encouraged to check that the provided hash matches the hash that they are
  3972. using (as theoretically the application may be using a different
  3973. configuration file with a different private key, which would result in
  3974. hard to find bugs).
  3975. As with most service APIs, the CORE API isolates applications from crashes
  3976. of the CORE service. If the CORE service crashes, the application will see
  3977. disconnect events for all existing connections. Once the connections are
  3978. re-established, the applications will be receive matching connect events.
  3979. @cindex core clinet-service protocol
  3980. @node The CORE Client-Service Protocol
  3981. @subsection The CORE Client-Service Protocol
  3982. This section describes the protocol between an application using the CORE
  3983. service (the client) and the CORE service process itself.
  3984. @menu
  3985. * Setup2::
  3986. * Notifications::
  3987. * Sending::
  3988. @end menu
  3989. @node Setup2
  3990. @subsubsection Setup2
  3991. When a client connects to the CORE service, it first sends a
  3992. @code{InitMessage} which specifies options for the connection and a set of
  3993. message type values which are supported by the application. The options
  3994. bitmask specifies which events the client would like to be notified about.
  3995. The options include:
  3996. @table @asis
  3997. @item GNUNET_CORE_OPTION_NOTHING No notifications
  3998. @item GNUNET_CORE_OPTION_STATUS_CHANGE Peers connecting and disconnecting
  3999. @item GNUNET_CORE_OPTION_FULL_INBOUND All inbound messages (after
  4000. decryption) with full payload
  4001. @item GNUNET_CORE_OPTION_HDR_INBOUND Just the @code{MessageHeader}
  4002. of all inbound messages
  4003. @item GNUNET_CORE_OPTION_FULL_OUTBOUND All outbound
  4004. messages (prior to encryption) with full payload
  4005. @item GNUNET_CORE_OPTION_HDR_OUTBOUND Just the @code{MessageHeader} of all
  4006. outbound messages
  4007. @end table
  4008. Typical applications will only monitor for connection status changes.
  4009. The CORE service responds to the @code{InitMessage} with an
  4010. @code{InitReplyMessage} which contains the peer's identity. Afterwards,
  4011. both CORE and the client can send messages.
  4012. @node Notifications
  4013. @subsubsection Notifications
  4014. The CORE will send @code{ConnectNotifyMessage}s and
  4015. @code{DisconnectNotifyMessage}s whenever peers connect or disconnect from
  4016. the CORE (assuming their type maps overlap with the message types
  4017. registered by the client). When the CORE receives a message that matches
  4018. the set of message types specified during the @code{InitMessage} (or if
  4019. monitoring is enabled in for inbound messages in the options), it sends a
  4020. @code{NotifyTrafficMessage} with the peer identity of the sender and the
  4021. decrypted payload. The same message format (except with
  4022. @code{GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND} for the message type) is
  4023. used to notify clients monitoring outbound messages; here, the peer
  4024. identity given is that of the receiver.
  4025. @node Sending
  4026. @subsubsection Sending
  4027. When a client wants to transmit a message, it first requests a
  4028. transmission slot by sending a @code{SendMessageRequest} which specifies
  4029. the priority, deadline and size of the message. Note that these values
  4030. may be ignored by CORE. When CORE is ready for the message, it answers
  4031. with a @code{SendMessageReady} response. The client can then transmit the
  4032. payload with a @code{SendMessage} message. Note that the actual message
  4033. size in the @code{SendMessage} is allowed to be smaller than the size in
  4034. the original request. A client may at any time send a fresh
  4035. @code{SendMessageRequest}, which then superceeds the previous
  4036. @code{SendMessageRequest}, which is then no longer valid. The client can
  4037. tell which @code{SendMessageRequest} the CORE service's
  4038. @code{SendMessageReady} message is for as all of these messages contain a
  4039. "unique" request ID (based on a counter incremented by the client
  4040. for each request).
  4041. @cindex CORE Peer-to-Peer Protocol
  4042. @node The CORE Peer-to-Peer Protocol
  4043. @subsection The CORE Peer-to-Peer Protocol
  4044. @menu
  4045. * Creating the EphemeralKeyMessage::
  4046. * Establishing a connection::
  4047. * Encryption and Decryption::
  4048. * Type maps::
  4049. @end menu
  4050. @cindex EphemeralKeyMessage creation
  4051. @node Creating the EphemeralKeyMessage
  4052. @subsubsection Creating the EphemeralKeyMessage
  4053. When the CORE service starts, each peer creates a fresh ephemeral (ECC)
  4054. public-private key pair and signs the corresponding
  4055. @code{EphemeralKeyMessage} with its long-term key (which we usually call
  4056. the peer's identity; the hash of the public long term key is what results
  4057. in a @code{struct GNUNET_PeerIdentity} in all GNUnet APIs. The ephemeral
  4058. key is ONLY used for an ECDHE
  4059. (@uref{http://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman, Elliptic-curve Diffie---Hellman})
  4060. exchange by the CORE service to establish symmetric session keys. A peer
  4061. will use the same @code{EphemeralKeyMessage} for all peers for
  4062. @code{REKEY_FREQUENCY}, which is usually 12 hours. After that time, it
  4063. will create a fresh ephemeral key (forgetting the old one) and broadcast
  4064. the new @code{EphemeralKeyMessage} to all connected peers, resulting in
  4065. fresh symmetric session keys. Note that peers independently decide on
  4066. when to discard ephemeral keys; it is not a protocol violation to discard
  4067. keys more often. Ephemeral keys are also never stored to disk; restarting
  4068. a peer will thus always create a fresh ephemeral key. The use of ephemeral
  4069. keys is what provides @uref{http://en.wikipedia.org/wiki/Forward_secrecy, forward secrecy}.
  4070. Just before transmission, the @code{EphemeralKeyMessage} is patched to
  4071. reflect the current sender_status, which specifies the current state of
  4072. the connection from the point of view of the sender. The possible values
  4073. are:
  4074. @itemize @bullet
  4075. @item @code{KX_STATE_DOWN} Initial value, never used on the network
  4076. @item @code{KX_STATE_KEY_SENT} We sent our ephemeral key, do not know the
  4077. key of the other peer
  4078. @item @code{KX_STATE_KEY_RECEIVED} This peer has received a valid
  4079. ephemeral key of the other peer, but we are waiting for the other peer to
  4080. confirm it's authenticity (ability to decode) via challenge-response.
  4081. @item @code{KX_STATE_UP} The connection is fully up from the point of
  4082. view of the sender (now performing keep-alives)
  4083. @item @code{KX_STATE_REKEY_SENT} The sender has initiated a rekeying
  4084. operation; the other peer has so far failed to confirm a working
  4085. connection using the new ephemeral key
  4086. @end itemize
  4087. @node Establishing a connection
  4088. @subsubsection Establishing a connection
  4089. Peers begin their interaction by sending a @code{EphemeralKeyMessage} to
  4090. the other peer once the TRANSPORT service notifies the CORE service about
  4091. the connection.
  4092. A peer receiving an @code{EphemeralKeyMessage} with a status
  4093. indicating that the sender does not have the receiver's ephemeral key, the
  4094. receiver's @code{EphemeralKeyMessage} is sent in response.
  4095. Additionally, if the receiver has not yet confirmed the authenticity of
  4096. the sender, it also sends an (encrypted)@code{PingMessage} with a
  4097. challenge (and the identity of the target) to the other peer. Peers
  4098. receiving a @code{PingMessage} respond with an (encrypted)
  4099. @code{PongMessage} which includes the challenge. Peers receiving a
  4100. @code{PongMessage} check the challenge, and if it matches set the
  4101. connection to @code{KX_STATE_UP}.
  4102. @node Encryption and Decryption
  4103. @subsubsection Encryption and Decryption
  4104. All functions related to the key exchange and encryption/decryption of
  4105. messages can be found in @file{gnunet-service-core_kx.c} (except for the
  4106. cryptographic primitives, which are in @file{util/crypto*.c}).
  4107. Given the key material from ECDHE, a Key derivation function
  4108. (@uref{https://en.wikipedia.org/wiki/Key_derivation_function, Key derivation function})
  4109. is used to derive two pairs of encryption and decryption keys for AES-256
  4110. and TwoFish, as well as initialization vectors and authentication keys
  4111. (for HMAC
  4112. (@uref{https://en.wikipedia.org/wiki/HMAC, HMAC})).
  4113. The HMAC is computed over the encrypted payload.
  4114. Encrypted messages include an iv_seed and the HMAC in the header.
  4115. Each encrypted message in the CORE service includes a sequence number and
  4116. a timestamp in the encrypted payload. The CORE service remembers the
  4117. largest observed sequence number and a bit-mask which represents which of
  4118. the previous 32 sequence numbers were already used.
  4119. Messages with sequence numbers lower than the largest observed sequence
  4120. number minus 32 are discarded. Messages with a timestamp that is less
  4121. than @code{REKEY_TOLERANCE} off (5 minutes) are also discarded. This of
  4122. course means that system clocks need to be reasonably synchronized for
  4123. peers to be able to communicate. Additionally, as the ephemeral key
  4124. changes every 12 hours, a peer would not even be able to decrypt messages
  4125. older than 12 hours.
  4126. @node Type maps
  4127. @subsubsection Type maps
  4128. Once an encrypted connection has been established, peers begin to exchange
  4129. type maps. Type maps are used to allow the CORE service to determine which
  4130. (encrypted) connections should be shown to which applications. A type map
  4131. is an array of 65536 bits representing the different types of messages
  4132. understood by applications using the CORE service. Each CORE service
  4133. maintains this map, simply by setting the respective bit for each message
  4134. type supported by any of the applications using the CORE service. Note
  4135. that bits for message types embedded in higher-level protocols (such as
  4136. MESH) will not be included in these type maps.
  4137. Typically, the type map of a peer will be sparse. Thus, the CORE service
  4138. attempts to compress its type map using @code{gzip}-style compression
  4139. ("deflate") prior to transmission. However, if the compression fails to
  4140. compact the map, the map may also be transmitted without compression
  4141. (resulting in @code{GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP} or
  4142. @code{GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP} messages respectively).
  4143. Upon receiving a type map, the respective CORE service notifies
  4144. applications about the connection to the other peer if they support any
  4145. message type indicated in the type map (or no message type at all).
  4146. If the CORE service experience a connect or disconnect event from an
  4147. application, it updates its type map (setting or unsetting the respective
  4148. bits) and notifies its neighbours about the change.
  4149. The CORE services of the neighbours then in turn generate connect and
  4150. disconnect events for the peer that sent the type map for their respective
  4151. applications. As CORE messages may be lost, the CORE service confirms
  4152. receiving a type map by sending back a
  4153. @code{GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP}. If such a confirmation
  4154. (with the correct hash of the type map) is not received, the sender will
  4155. retransmit the type map (with exponential back-off).
  4156. @cindex CADET Subsystem
  4157. @cindex CADET
  4158. @cindex cadet
  4159. @node CADET Subsystem
  4160. @section CADET Subsystem
  4161. The CADET subsystem in GNUnet is responsible for secure end-to-end
  4162. communications between nodes in the GNUnet overlay network. CADET builds
  4163. on the CORE subsystem which provides for the link-layer communication and
  4164. then adds routing, forwarding and additional security to the connections.
  4165. CADET offers the same cryptographic services as CORE, but on an
  4166. end-to-end level. This is done so peers retransmitting traffic on behalf
  4167. of other peers cannot access the payload data.
  4168. @itemize @bullet
  4169. @item CADET provides confidentiality with so-called perfect forward
  4170. secrecy; we use ECDHE powered by Curve25519 for the key exchange and then
  4171. use symmetric encryption, encrypting with both AES-256 and Twofish
  4172. @item authentication is achieved by signing the ephemeral keys using
  4173. Ed25519, a deterministic variant of ECDSA
  4174. @item integrity protection (using SHA-512 to do encrypt-then-MAC, although
  4175. only 256 bits are sent to reduce overhead)
  4176. @item replay protection (using nonces, timestamps, challenge-response,
  4177. message counters and ephemeral keys)
  4178. @item liveness (keep-alive messages, timeout)
  4179. @end itemize
  4180. Additional to the CORE-like security benefits, CADET offers other
  4181. properties that make it a more universal service than CORE.
  4182. @itemize @bullet
  4183. @item CADET can establish channels to arbitrary peers in GNUnet. If a
  4184. peer is not immediately reachable, CADET will find a path through the
  4185. network and ask other peers to retransmit the traffic on its behalf.
  4186. @item CADET offers (optional) reliability mechanisms. In a reliable
  4187. channel traffic is guaranteed to arrive complete, unchanged and in-order.
  4188. @item CADET takes care of flow and congestion control mechanisms, not
  4189. allowing the sender to send more traffic than the receiver or the network
  4190. are able to process.
  4191. @end itemize
  4192. @menu
  4193. * libgnunetcadet::
  4194. @end menu
  4195. @cindex libgnunetcadet
  4196. @node libgnunetcadet
  4197. @subsection libgnunetcadet
  4198. The CADET API (defined in @file{gnunet_cadet_service.h}) is the
  4199. messaging API used by P2P applications built using GNUnet.
  4200. It provides applications the ability to send and receive encrypted
  4201. messages to any peer participating in GNUnet.
  4202. The API is heavily base on the CORE API.
  4203. CADET delivers messages to other peers in "channels".
  4204. A channel is a permanent connection defined by a destination peer
  4205. (identified by its public key) and a port number.
  4206. Internally, CADET tunnels all channels towards a destination peer
  4207. using one session key and relays the data on multiple "connections",
  4208. independent from the channels.
  4209. Each channel has optional parameters, the most important being the
  4210. reliability flag.
  4211. Should a message get lost on TRANSPORT/CORE level, if a channel is
  4212. created with as reliable, CADET will retransmit the lost message and
  4213. deliver it in order to the destination application.
  4214. @pindex GNUNET_CADET_connect
  4215. To communicate with other peers using CADET, it is necessary to first
  4216. connect to the service using @code{GNUNET_CADET_connect}.
  4217. This function takes several parameters in form of callbacks, to allow the
  4218. client to react to various events, like incoming channels or channels that
  4219. terminate, as well as specify a list of ports the client wishes to listen
  4220. to (at the moment it is not possible to start listening on further ports
  4221. once connected, but nothing prevents a client to connect several times to
  4222. CADET, even do one connection per listening port).
  4223. The function returns a handle which has to be used for any further
  4224. interaction with the service.
  4225. @pindex GNUNET_CADET_channel_create
  4226. To connect to a remote peer, a client has to call the
  4227. @code{GNUNET_CADET_channel_create} function. The most important parameters
  4228. given are the remote peer's identity (it public key) and a port, which
  4229. specifies which application on the remote peer to connect to, similar to
  4230. TCP/UDP ports. CADET will then find the peer in the GNUnet network and
  4231. establish the proper low-level connections and do the necessary key
  4232. exchanges to assure and authenticated, secure and verified communication.
  4233. Similar to @code{GNUNET_CADET_connect},@code{GNUNET_CADET_create_channel}
  4234. returns a handle to interact with the created channel.
  4235. @pindex GNUNET_CADET_notify_transmit_ready
  4236. For every message the client wants to send to the remote application,
  4237. @code{GNUNET_CADET_notify_transmit_ready} must be called, indicating the
  4238. channel on which the message should be sent and the size of the message
  4239. (but not the message itself!). Once CADET is ready to send the message,
  4240. the provided callback will fire, and the message contents are provided to
  4241. this callback.
  4242. Please note the CADET does not provide an explicit notification of when a
  4243. channel is connected. In loosely connected networks, like big wireless
  4244. mesh networks, this can take several seconds, even minutes in the worst
  4245. case. To be alerted when a channel is online, a client can call
  4246. @code{GNUNET_CADET_notify_transmit_ready} immediately after
  4247. @code{GNUNET_CADET_create_channel}. When the callback is activated, it
  4248. means that the channel is online. The callback can give 0 bytes to CADET
  4249. if no message is to be sent, this is OK.
  4250. @pindex GNUNET_CADET_notify_transmit_cancel
  4251. If a transmission was requested but before the callback fires it is no
  4252. longer needed, it can be canceled with
  4253. @code{GNUNET_CADET_notify_transmit_ready_cancel}, which uses the handle
  4254. given back by @code{GNUNET_CADET_notify_transmit_ready}.
  4255. As in the case of CORE, only one message can be requested at a time: a
  4256. client must not call @code{GNUNET_CADET_notify_transmit_ready} again until
  4257. the callback is called or the request is canceled.
  4258. @pindex GNUNET_CADET_channel_destroy
  4259. When a channel is no longer needed, a client can call
  4260. @code{GNUNET_CADET_channel_destroy} to get rid of it.
  4261. Note that CADET will try to transmit all pending traffic before notifying
  4262. the remote peer of the destruction of the channel, including
  4263. retransmitting lost messages if the channel was reliable.
  4264. Incoming channels, channels being closed by the remote peer, and traffic
  4265. on any incoming or outgoing channels are given to the client when CADET
  4266. executes the callbacks given to it at the time of
  4267. @code{GNUNET_CADET_connect}.
  4268. @pindex GNUNET_CADET_disconnect
  4269. Finally, when an application no longer wants to use CADET, it should call
  4270. @code{GNUNET_CADET_disconnect}, but first all channels and pending
  4271. transmissions must be closed (otherwise CADET will complain).
  4272. @cindex NSE Subsystem
  4273. @node NSE Subsystem
  4274. @section NSE Subsystem
  4275. NSE stands for @dfn{Network Size Estimation}. The NSE subsystem provides
  4276. other subsystems and users with a rough estimate of the number of peers
  4277. currently participating in the GNUnet overlay.
  4278. The computed value is not a precise number as producing a precise number
  4279. in a decentralized, efficient and secure way is impossible.
  4280. While NSE's estimate is inherently imprecise, NSE also gives the expected
  4281. range. For a peer that has been running in a stable network for a
  4282. while, the real network size will typically (99.7% of the time) be in the
  4283. range of [2/3 estimate, 3/2 estimate]. We will now give an overview of the
  4284. algorithm used to calculate the estimate;
  4285. all of the details can be found in this technical report.
  4286. @c FIXME: link to the report.
  4287. @menu
  4288. * Motivation::
  4289. * Principle::
  4290. * libgnunetnse::
  4291. * The NSE Client-Service Protocol::
  4292. * The NSE Peer-to-Peer Protocol::
  4293. @end menu
  4294. @node Motivation
  4295. @subsection Motivation
  4296. Some subsystems, like DHT, need to know the size of the GNUnet network to
  4297. optimize some parameters of their own protocol. The decentralized nature
  4298. of GNUnet makes efficient and securely counting the exact number of peers
  4299. infeasible. Although there are several decentralized algorithms to count
  4300. the number of peers in a system, so far there is none to do so securely.
  4301. Other protocols may allow any malicious peer to manipulate the final
  4302. result or to take advantage of the system to perform
  4303. @dfn{Denial of Service} (DoS) attacks against the network.
  4304. GNUnet's NSE protocol avoids these drawbacks.
  4305. @menu
  4306. * Security::
  4307. @end menu
  4308. @cindex NSE security
  4309. @cindex nse security
  4310. @node Security
  4311. @subsubsection Security
  4312. The NSE subsystem is designed to be resilient against these attacks.
  4313. It uses @uref{http://en.wikipedia.org/wiki/Proof-of-work_system, proofs of work}
  4314. to prevent one peer from impersonating a large number of participants,
  4315. which would otherwise allow an adversary to artificially inflate the
  4316. estimate.
  4317. The DoS protection comes from the time-based nature of the protocol:
  4318. the estimates are calculated periodically and out-of-time traffic is
  4319. either ignored or stored for later retransmission by benign peers.
  4320. In particular, peers cannot trigger global network communication at will.
  4321. @cindex NSE principle
  4322. @cindex nse principle
  4323. @node Principle
  4324. @subsection Principle
  4325. The algorithm calculates the estimate by finding the globally closest
  4326. peer ID to a random, time-based value.
  4327. The idea is that the closer the ID is to the random value, the more
  4328. "densely packed" the ID space is, and therefore, more peers are in the
  4329. network.
  4330. @menu
  4331. * Example::
  4332. * Algorithm::
  4333. * Target value::
  4334. * Timing::
  4335. * Controlled Flooding::
  4336. * Calculating the estimate::
  4337. @end menu
  4338. @node Example
  4339. @subsubsection Example
  4340. Suppose all peers have IDs between 0 and 100 (our ID space), and the
  4341. random value is 42.
  4342. If the closest peer has the ID 70 we can imagine that the average
  4343. "distance" between peers is around 30 and therefore the are around 3
  4344. peers in the whole ID space. On the other hand, if the closest peer has
  4345. the ID 44, we can imagine that the space is rather packed with peers,
  4346. maybe as much as 50 of them.
  4347. Naturally, we could have been rather unlucky, and there is only one peer
  4348. and happens to have the ID 44. Thus, the current estimate is calculated
  4349. as the average over multiple rounds, and not just a single sample.
  4350. @node Algorithm
  4351. @subsubsection Algorithm
  4352. Given that example, one can imagine that the job of the subsystem is to
  4353. efficiently communicate the ID of the closest peer to the target value
  4354. to all the other peers, who will calculate the estimate from it.
  4355. @node Target value
  4356. @subsubsection Target value
  4357. The target value itself is generated by hashing the current time, rounded
  4358. down to an agreed value. If the rounding amount is 1h (default) and the
  4359. time is 12:34:56, the time to hash would be 12:00:00. The process is
  4360. repeated each rounding amount (in this example would be every hour).
  4361. Every repetition is called a round.
  4362. @node Timing
  4363. @subsubsection Timing
  4364. The NSE subsystem has some timing control to avoid everybody broadcasting
  4365. its ID all at one. Once each peer has the target random value, it
  4366. compares its own ID to the target and calculates the hypothetical size of
  4367. the network if that peer were to be the closest.
  4368. Then it compares the hypothetical size with the estimate from the previous
  4369. rounds. For each value there is an associated point in the period,
  4370. let's call it "broadcast time". If its own hypothetical estimate
  4371. is the same as the previous global estimate, its "broadcast time" will be
  4372. in the middle of the round. If its bigger it will be earlier and if its
  4373. smaller (the most likely case) it will be later. This ensures that the
  4374. peers closest to the target value start broadcasting their ID the first.
  4375. @node Controlled Flooding
  4376. @subsubsection Controlled Flooding
  4377. When a peer receives a value, first it verifies that it is closer than the
  4378. closest value it had so far, otherwise it answers the incoming message
  4379. with a message containing the better value. Then it checks a proof of
  4380. work that must be included in the incoming message, to ensure that the
  4381. other peer's ID is not made up (otherwise a malicious peer could claim to
  4382. have an ID of exactly the target value every round). Once validated, it
  4383. compares the broadcast time of the received value with the current time
  4384. and if it's not too early, sends the received value to its neighbors.
  4385. Otherwise it stores the value until the correct broadcast time comes.
  4386. This prevents unnecessary traffic of sub-optimal values, since a better
  4387. value can come before the broadcast time, rendering the previous one
  4388. obsolete and saving the traffic that would have been used to broadcast it
  4389. to the neighbors.
  4390. @node Calculating the estimate
  4391. @subsubsection Calculating the estimate
  4392. Once the closest ID has been spread across the network each peer gets the
  4393. exact distance between this ID and the target value of the round and
  4394. calculates the estimate with a mathematical formula described in the tech
  4395. report. The estimate generated with this method for a single round is not
  4396. very precise. Remember the case of the example, where the only peer is the
  4397. ID 44 and we happen to generate the target value 42, thinking there are
  4398. 50 peers in the network. Therefore, the NSE subsystem remembers the last
  4399. 64 estimates and calculates an average over them, giving a result of which
  4400. usually has one bit of uncertainty (the real size could be half of the
  4401. estimate or twice as much). Note that the actual network size is
  4402. calculated in powers of two of the raw input, thus one bit of uncertainty
  4403. means a factor of two in the size estimate.
  4404. @cindex libgnunetnse
  4405. @node libgnunetnse
  4406. @subsection libgnunetnse
  4407. The NSE subsystem has the simplest API of all services, with only two
  4408. calls: @code{GNUNET_NSE_connect} and @code{GNUNET_NSE_disconnect}.
  4409. The connect call gets a callback function as a parameter and this function
  4410. is called each time the network agrees on an estimate. This usually is
  4411. once per round, with some exceptions: if the closest peer has a late
  4412. local clock and starts spreading its ID after everyone else agreed on a
  4413. value, the callback might be activated twice in a round, the second value
  4414. being always bigger than the first. The default round time is set to
  4415. 1 hour.
  4416. The disconnect call disconnects from the NSE subsystem and the callback
  4417. is no longer called with new estimates.
  4418. @menu
  4419. * Results::
  4420. * libgnunetnse - Examples::
  4421. @end menu
  4422. @node Results
  4423. @subsubsection Results
  4424. The callback provides two values: the average and the
  4425. @uref{http://en.wikipedia.org/wiki/Standard_deviation, standard deviation}
  4426. of the last 64 rounds. The values provided by the callback function are
  4427. logarithmic, this means that the real estimate numbers can be obtained by
  4428. calculating 2 to the power of the given value (2average). From a
  4429. statistics point of view this means that:
  4430. @itemize @bullet
  4431. @item 68% of the time the real size is included in the interval
  4432. [(2average-stddev), 2]
  4433. @item 95% of the time the real size is included in the interval
  4434. [(2average-2*stddev, 2^average+2*stddev]
  4435. @item 99.7% of the time the real size is included in the interval
  4436. [(2average-3*stddev, 2average+3*stddev]
  4437. @end itemize
  4438. The expected standard variation for 64 rounds in a network of stable size
  4439. is 0.2. Thus, we can say that normally:
  4440. @itemize @bullet
  4441. @item 68% of the time the real size is in the range [-13%, +15%]
  4442. @item 95% of the time the real size is in the range [-24%, +32%]
  4443. @item 99.7% of the time the real size is in the range [-34%, +52%]
  4444. @end itemize
  4445. As said in the introduction, we can be quite sure that usually the real
  4446. size is between one third and three times the estimate. This can of
  4447. course vary with network conditions.
  4448. Thus, applications may want to also consider the provided standard
  4449. deviation value, not only the average (in particular, if the standard
  4450. variation is very high, the average maybe meaningless: the network size is
  4451. changing rapidly).
  4452. @node libgnunetnse - Examples
  4453. @subsubsection libgnunetnse -Examples
  4454. Let's close with a couple examples.
  4455. @table @asis
  4456. @item Average: 10, std dev: 1 Here the estimate would be
  4457. 2^10 = 1024 peers. (The range in which we can be 95% sure is:
  4458. [2^8, 2^12] = [256, 4096]. We can be very (>99.7%) sure that the network
  4459. is not a hundred peers and absolutely sure that it is not a million peers,
  4460. but somewhere around a thousand.)
  4461. @item Average 22, std dev: 0.2 Here the estimate would be
  4462. 2^22 = 4 Million peers. (The range in which we can be 99.7% sure
  4463. is: [2^21.4, 2^22.6] = [2.8M, 6.3M]. We can be sure that the network size
  4464. is around four million, with absolutely way of it being 1 million.)
  4465. @end table
  4466. To put this in perspective, if someone remembers the LHC Higgs boson
  4467. results, were announced with "5 sigma" and "6 sigma" certainties. In this
  4468. case a 5 sigma minimum would be 2 million and a 6 sigma minimum,
  4469. 1.8 million.
  4470. @node The NSE Client-Service Protocol
  4471. @subsection The NSE Client-Service Protocol
  4472. As with the API, the client-service protocol is very simple, only has 2
  4473. different messages, defined in @code{src/nse/nse.h}:
  4474. @itemize @bullet
  4475. @item @code{GNUNET_MESSAGE_TYPE_NSE_START}@ This message has no parameters
  4476. and is sent from the client to the service upon connection.
  4477. @item @code{GNUNET_MESSAGE_TYPE_NSE_ESTIMATE}@ This message is sent from
  4478. the service to the client for every new estimate and upon connection.
  4479. Contains a timestamp for the estimate, the average and the standard
  4480. deviation for the respective round.
  4481. @end itemize
  4482. When the @code{GNUNET_NSE_disconnect} API call is executed, the client
  4483. simply disconnects from the service, with no message involved.
  4484. @cindex NSE Peer-to-Peer Protocol
  4485. @node The NSE Peer-to-Peer Protocol
  4486. @subsection The NSE Peer-to-Peer Protocol
  4487. @pindex GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD
  4488. The NSE subsystem only has one message in the P2P protocol, the
  4489. @code{GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD} message.
  4490. This message key contents are the timestamp to identify the round
  4491. (differences in system clocks may cause some peers to send messages way
  4492. too early or way too late, so the timestamp allows other peers to
  4493. identify such messages easily), the
  4494. @uref{http://en.wikipedia.org/wiki/Proof-of-work_system, proof of work}
  4495. used to make it difficult to mount a
  4496. @uref{http://en.wikipedia.org/wiki/Sybil_attack, Sybil attack}, and the
  4497. public key, which is used to verify the signature on the message.
  4498. Every peer stores a message for the previous, current and next round. The
  4499. messages for the previous and current round are given to peers that
  4500. connect to us. The message for the next round is simply stored until our
  4501. system clock advances to the next round. The message for the current round
  4502. is what we are flooding the network with right now.
  4503. At the beginning of each round the peer does the following:
  4504. @itemize @bullet
  4505. @item calculates its own distance to the target value
  4506. @item creates, signs and stores the message for the current round (unless
  4507. it has a better message in the "next round" slot which came early in the
  4508. previous round)
  4509. @item calculates, based on the stored round message (own or received) when
  4510. to start flooding it to its neighbors
  4511. @end itemize
  4512. Upon receiving a message the peer checks the validity of the message
  4513. (round, proof of work, signature). The next action depends on the
  4514. contents of the incoming message:
  4515. @itemize @bullet
  4516. @item if the message is worse than the current stored message, the peer
  4517. sends the current message back immediately, to stop the other peer from
  4518. spreading suboptimal results
  4519. @item if the message is better than the current stored message, the peer
  4520. stores the new message and calculates the new target time to start
  4521. spreading it to its neighbors (excluding the one the message came from)
  4522. @item if the message is for the previous round, it is compared to the
  4523. message stored in the "previous round slot", which may then be updated
  4524. @item if the message is for the next round, it is compared to the message
  4525. stored in the "next round slot", which again may then be updated
  4526. @end itemize
  4527. Finally, when it comes to send the stored message for the current round to
  4528. the neighbors there is a random delay added for each neighbor, to avoid
  4529. traffic spikes and minimize cross-messages.
  4530. @cindex HOSTLIST Subsystem
  4531. @node HOSTLIST Subsystem
  4532. @section HOSTLIST Subsystem
  4533. Peers in the GNUnet overlay network need address information so that they
  4534. can connect with other peers. GNUnet uses so called HELLO messages to
  4535. store and exchange peer addresses.
  4536. GNUnet provides several methods for peers to obtain this information:
  4537. @itemize @bullet
  4538. @item out-of-band exchange of HELLO messages (manually, using for example
  4539. gnunet-peerinfo)
  4540. @item HELLO messages shipped with GNUnet (automatic with distribution)
  4541. @item UDP neighbor discovery in LAN (IPv4 broadcast, IPv6 multicast)
  4542. @item topology gossiping (learning from other peers we already connected
  4543. to), and
  4544. @item the HOSTLIST daemon covered in this section, which is particularly
  4545. relevant for bootstrapping new peers.
  4546. @end itemize
  4547. New peers have no existing connections (and thus cannot learn from gossip
  4548. among peers), may not have other peers in their LAN and might be started
  4549. with an outdated set of HELLO messages from the distribution.
  4550. In this case, getting new peers to connect to the network requires either
  4551. manual effort or the use of a HOSTLIST to obtain HELLOs.
  4552. @menu
  4553. * HELLOs::
  4554. * Overview for the HOSTLIST subsystem::
  4555. * Interacting with the HOSTLIST daemon::
  4556. * Hostlist security address validation::
  4557. * The HOSTLIST daemon::
  4558. * The HOSTLIST server::
  4559. * The HOSTLIST client::
  4560. * Usage::
  4561. @end menu
  4562. @node HELLOs
  4563. @subsection HELLOs
  4564. The basic information peers require to connect to other peers are
  4565. contained in so called HELLO messages you can think of as a business card.
  4566. Besides the identity of the peer (based on the cryptographic public key) a
  4567. HELLO message may contain address information that specifies ways to
  4568. contact a peer. By obtaining HELLO messages, a peer can learn how to
  4569. contact other peers.
  4570. @node Overview for the HOSTLIST subsystem
  4571. @subsection Overview for the HOSTLIST subsystem
  4572. The HOSTLIST subsystem provides a way to distribute and obtain contact
  4573. information to connect to other peers using a simple HTTP GET request.
  4574. It's implementation is split in three parts, the main file for the daemon
  4575. itself (@file{gnunet-daemon-hostlist.c}), the HTTP client used to download
  4576. peer information (@file{hostlist-client.c}) and the server component used
  4577. to provide this information to other peers (@file{hostlist-server.c}).
  4578. The server is basically a small HTTP web server (based on GNU
  4579. libmicrohttpd) which provides a list of HELLOs known to the local peer for
  4580. download. The client component is basically a HTTP client
  4581. (based on libcurl) which can download hostlists from one or more websites.
  4582. The hostlist format is a binary blob containing a sequence of HELLO
  4583. messages. Note that any HTTP server can theoretically serve a hostlist,
  4584. the build-in hostlist server makes it simply convenient to offer this
  4585. service.
  4586. @menu
  4587. * Features::
  4588. * HOSTLIST - Limitations::
  4589. @end menu
  4590. @node Features
  4591. @subsubsection Features
  4592. The HOSTLIST daemon can:
  4593. @itemize @bullet
  4594. @item provide HELLO messages with validated addresses obtained from
  4595. PEERINFO to download for other peers
  4596. @item download HELLO messages and forward these message to the TRANSPORT
  4597. subsystem for validation
  4598. @item advertises the URL of this peer's hostlist address to other peers
  4599. via gossip
  4600. @item automatically learn about hostlist servers from the gossip of other
  4601. peers
  4602. @end itemize
  4603. @node HOSTLIST - Limitations
  4604. @subsubsection HOSTLIST - Limitations
  4605. The HOSTLIST daemon does not:
  4606. @itemize @bullet
  4607. @item verify the cryptographic information in the HELLO messages
  4608. @item verify the address information in the HELLO messages
  4609. @end itemize
  4610. @node Interacting with the HOSTLIST daemon
  4611. @subsection Interacting with the HOSTLIST daemon
  4612. The HOSTLIST subsystem is currently implemented as a daemon, so there is
  4613. no need for the user to interact with it and therefore there is no
  4614. command line tool and no API to communicate with the daemon. In the
  4615. future, we can envision changing this to allow users to manually trigger
  4616. the download of a hostlist.
  4617. Since there is no command line interface to interact with HOSTLIST, the
  4618. only way to interact with the hostlist is to use STATISTICS to obtain or
  4619. modify information about the status of HOSTLIST:
  4620. @example
  4621. $ gnunet-statistics -s hostlist
  4622. @end example
  4623. @noindent
  4624. In particular, HOSTLIST includes a @strong{persistent} value in statistics
  4625. that specifies when the hostlist server might be queried next. As this
  4626. value is exponentially increasing during runtime, developers may want to
  4627. reset or manually adjust it. Note that HOSTLIST (but not STATISTICS) needs
  4628. to be shutdown if changes to this value are to have any effect on the
  4629. daemon (as HOSTLIST does not monitor STATISTICS for changes to the
  4630. download frequency).
  4631. @node Hostlist security address validation
  4632. @subsection Hostlist security address validation
  4633. Since information obtained from other parties cannot be trusted without
  4634. validation, we have to distinguish between @emph{validated} and
  4635. @emph{not validated} addresses. Before using (and so trusting)
  4636. information from other parties, this information has to be double-checked
  4637. (validated). Address validation is not done by HOSTLIST but by the
  4638. TRANSPORT service.
  4639. The HOSTLIST component is functionally located between the PEERINFO and
  4640. the TRANSPORT subsystem. When acting as a server, the daemon obtains valid
  4641. (@emph{validated}) peer information (HELLO messages) from the PEERINFO
  4642. service and provides it to other peers. When acting as a client, it
  4643. contacts the HOSTLIST servers specified in the configuration, downloads
  4644. the (unvalidated) list of HELLO messages and forwards these information
  4645. to the TRANSPORT server to validate the addresses.
  4646. @cindex HOSTLIST daemon
  4647. @node The HOSTLIST daemon
  4648. @subsection The HOSTLIST daemon
  4649. The hostlist daemon is the main component of the HOSTLIST subsystem. It is
  4650. started by the ARM service and (if configured) starts the HOSTLIST client
  4651. and server components.
  4652. @pindex GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT
  4653. If the daemon provides a hostlist itself it can advertise it's own
  4654. hostlist to other peers. To do so it sends a
  4655. @code{GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT} message to other peers
  4656. when they connect to this peer on the CORE level. This hostlist
  4657. advertisement message contains the URL to access the HOSTLIST HTTP
  4658. server of the sender. The daemon may also subscribe to this type of
  4659. message from CORE service, and then forward these kind of message to the
  4660. HOSTLIST client. The client then uses all available URLs to download peer
  4661. information when necessary.
  4662. When starting, the HOSTLIST daemon first connects to the CORE subsystem
  4663. and if hostlist learning is enabled, registers a CORE handler to receive
  4664. this kind of messages. Next it starts (if configured) the client and
  4665. server. It passes pointers to CORE connect and disconnect and receive
  4666. handlers where the client and server store their functions, so the daemon
  4667. can notify them about CORE events.
  4668. To clean up on shutdown, the daemon has a cleaning task, shutting down all
  4669. subsystems and disconnecting from CORE.
  4670. @cindex HOSTLIST server
  4671. @node The HOSTLIST server
  4672. @subsection The HOSTLIST server
  4673. The server provides a way for other peers to obtain HELLOs. Basically it
  4674. is a small web server other peers can connect to and download a list of
  4675. HELLOs using standard HTTP; it may also advertise the URL of the hostlist
  4676. to other peers connecting on CORE level.
  4677. @menu
  4678. * The HTTP Server::
  4679. * Advertising the URL::
  4680. @end menu
  4681. @node The HTTP Server
  4682. @subsubsection The HTTP Server
  4683. During startup, the server starts a web server listening on the port
  4684. specified with the HTTPPORT value (default 8080). In addition it connects
  4685. to the PEERINFO service to obtain peer information. The HOSTLIST server
  4686. uses the GNUNET_PEERINFO_iterate function to request HELLO information for
  4687. all peers and adds their information to a new hostlist if they are
  4688. suitable (expired addresses and HELLOs without addresses are both not
  4689. suitable) and the maximum size for a hostlist is not exceeded
  4690. (MAX_BYTES_PER_HOSTLISTS = 500000).
  4691. When PEERINFO finishes (with a last NULL callback), the server destroys
  4692. the previous hostlist response available for download on the web server
  4693. and replaces it with the updated hostlist. The hostlist format is
  4694. basically a sequence of HELLO messages (as obtained from PEERINFO) without
  4695. any special tokenization. Since each HELLO message contains a size field,
  4696. the response can easily be split into separate HELLO messages by the
  4697. client.
  4698. A HOSTLIST client connecting to the HOSTLIST server will receive the
  4699. hostlist as an HTTP response and the server will terminate the
  4700. connection with the result code @code{HTTP 200 OK}.
  4701. The connection will be closed immediately if no hostlist is available.
  4702. @node Advertising the URL
  4703. @subsubsection Advertising the URL
  4704. The server also advertises the URL to download the hostlist to other peers
  4705. if hostlist advertisement is enabled.
  4706. When a new peer connects and has hostlist learning enabled, the server
  4707. sends a @code{GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT} message to this
  4708. peer using the CORE service.
  4709. @cindex HOSTLIST client
  4710. @node The HOSTLIST client
  4711. @subsection The HOSTLIST client
  4712. The client provides the functionality to download the list of HELLOs from
  4713. a set of URLs.
  4714. It performs a standard HTTP request to the URLs configured and learned
  4715. from advertisement messages received from other peers. When a HELLO is
  4716. downloaded, the HOSTLIST client forwards the HELLO to the TRANSPORT
  4717. service for validation.
  4718. The client supports two modes of operation:
  4719. @itemize @bullet
  4720. @item download of HELLOs (bootstrapping)
  4721. @item learning of URLs
  4722. @end itemize
  4723. @menu
  4724. * Bootstrapping::
  4725. * Learning::
  4726. @end menu
  4727. @node Bootstrapping
  4728. @subsubsection Bootstrapping
  4729. For bootstrapping, it schedules a task to download the hostlist from the
  4730. set of known URLs.
  4731. The downloads are only performed if the number of current
  4732. connections is smaller than a minimum number of connections
  4733. (at the moment 4).
  4734. The interval between downloads increases exponentially; however, the
  4735. exponential growth is limited if it becomes longer than an hour.
  4736. At that point, the frequency growth is capped at
  4737. (#number of connections * 1h).
  4738. Once the decision has been taken to download HELLOs, the daemon chooses a
  4739. random URL from the list of known URLs. URLs can be configured in the
  4740. configuration or be learned from advertisement messages.
  4741. The client uses a HTTP client library (libcurl) to initiate the download
  4742. using the libcurl multi interface.
  4743. Libcurl passes the data to the callback_download function which
  4744. stores the data in a buffer if space is available and the maximum size for
  4745. a hostlist download is not exceeded (MAX_BYTES_PER_HOSTLISTS = 500000).
  4746. When a full HELLO was downloaded, the HOSTLIST client offers this
  4747. HELLO message to the TRANSPORT service for validation.
  4748. When the download is finished or failed, statistical information about the
  4749. quality of this URL is updated.
  4750. @cindex HOSTLIST learning
  4751. @node Learning
  4752. @subsubsection Learning
  4753. The client also manages hostlist advertisements from other peers. The
  4754. HOSTLIST daemon forwards @code{GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT}
  4755. messages to the client subsystem, which extracts the URL from the message.
  4756. Next, a test of the newly obtained URL is performed by triggering a
  4757. download from the new URL. If the URL works correctly, it is added to the
  4758. list of working URLs.
  4759. The size of the list of URLs is restricted, so if an additional server is
  4760. added and the list is full, the URL with the worst quality ranking
  4761. (determined through successful downloads and number of HELLOs e.g.) is
  4762. discarded. During shutdown the list of URLs is saved to a file for
  4763. persistance and loaded on startup. URLs from the configuration file are
  4764. never discarded.
  4765. @node Usage
  4766. @subsection Usage
  4767. To start HOSTLIST by default, it has to be added to the DEFAULTSERVICES
  4768. section for the ARM services. This is done in the default configuration.
  4769. For more information on how to configure the HOSTLIST subsystem see the
  4770. installation handbook:@
  4771. Configuring the hostlist to bootstrap@
  4772. Configuring your peer to provide a hostlist
  4773. @cindex IDENTITY Subsystem
  4774. @node IDENTITY Subsystem
  4775. @section IDENTITY Subsystem
  4776. Identities of "users" in GNUnet are called egos.
  4777. Egos can be used as pseudonyms ("fake names") or be tied to an
  4778. organization (for example, "GNU") or even the actual identity of a human.
  4779. GNUnet users are expected to have many egos. They might have one tied to
  4780. their real identity, some for organizations they manage, and more for
  4781. different domains where they want to operate under a pseudonym.
  4782. The IDENTITY service allows users to manage their egos. The identity
  4783. service manages the private keys egos of the local user; it does not
  4784. manage identities of other users (public keys). Public keys for other
  4785. users need names to become manageable. GNUnet uses the
  4786. @dfn{GNU Name System} (GNS) to give names to other users and manage their
  4787. public keys securely. This chapter is about the IDENTITY service,
  4788. which is about the management of private keys.
  4789. On the network, an ego corresponds to an ECDSA key (over Curve25519,
  4790. using RFC 6979, as required by GNS). Thus, users can perform actions
  4791. under a particular ego by using (signing with) a particular private key.
  4792. Other users can then confirm that the action was really performed by that
  4793. ego by checking the signature against the respective public key.
  4794. The IDENTITY service allows users to associate a human-readable name with
  4795. each ego. This way, users can use names that will remind them of the
  4796. purpose of a particular ego.
  4797. The IDENTITY service will store the respective private keys and
  4798. allows applications to access key information by name.
  4799. Users can change the name that is locally (!) associated with an ego.
  4800. Egos can also be deleted, which means that the private key will be removed
  4801. and it thus will not be possible to perform actions with that ego in the
  4802. future.
  4803. Additionally, the IDENTITY subsystem can associate service functions with
  4804. egos.
  4805. For example, GNS requires the ego that should be used for the shorten
  4806. zone. GNS will ask IDENTITY for an ego for the "gns-short" service.
  4807. The IDENTITY service has a mapping of such service strings to the name of
  4808. the ego that the user wants to use for this service, for example
  4809. "my-short-zone-ego".
  4810. Finally, the IDENTITY API provides access to a special ego, the
  4811. anonymous ego. The anonymous ego is special in that its private key is not
  4812. really private, but fixed and known to everyone.
  4813. Thus, anyone can perform actions as anonymous. This can be useful as with
  4814. this trick, code does not have to contain a special case to distinguish
  4815. between anonymous and pseudonymous egos.
  4816. @menu
  4817. * libgnunetidentity::
  4818. * The IDENTITY Client-Service Protocol::
  4819. @end menu
  4820. @cindex libgnunetidentity
  4821. @node libgnunetidentity
  4822. @subsection libgnunetidentity
  4823. @menu
  4824. * Connecting to the service::
  4825. * Operations on Egos::
  4826. * The anonymous Ego::
  4827. * Convenience API to lookup a single ego::
  4828. * Associating egos with service functions::
  4829. @end menu
  4830. @node Connecting to the service
  4831. @subsubsection Connecting to the service
  4832. First, typical clients connect to the identity service using
  4833. @code{GNUNET_IDENTITY_connect}. This function takes a callback as a
  4834. parameter.
  4835. If the given callback parameter is non-null, it will be invoked to notify
  4836. the application about the current state of the identities in the system.
  4837. @itemize @bullet
  4838. @item First, it will be invoked on all known egos at the time of the
  4839. connection. For each ego, a handle to the ego and the user's name for the
  4840. ego will be passed to the callback. Furthermore, a @code{void **} context
  4841. argument will be provided which gives the client the opportunity to
  4842. associate some state with the ego.
  4843. @item Second, the callback will be invoked with NULL for the ego, the name
  4844. and the context. This signals that the (initial) iteration over all egos
  4845. has completed.
  4846. @item Then, the callback will be invoked whenever something changes about
  4847. an ego.
  4848. If an ego is renamed, the callback is invoked with the ego handle of the
  4849. ego that was renamed, and the new name. If an ego is deleted, the callback
  4850. is invoked with the ego handle and a name of NULL. In the deletion case,
  4851. the application should also release resources stored in the context.
  4852. @item When the application destroys the connection to the identity service
  4853. using @code{GNUNET_IDENTITY_disconnect}, the callback is again invoked
  4854. with the ego and a name of NULL (equivalent to deletion of the egos).
  4855. This should again be used to clean up the per-ego context.
  4856. @end itemize
  4857. The ego handle passed to the callback remains valid until the callback is
  4858. invoked with a name of NULL, so it is safe to store a reference to the
  4859. ego's handle.
  4860. @node Operations on Egos
  4861. @subsubsection Operations on Egos
  4862. Given an ego handle, the main operations are to get its associated private
  4863. key using @code{GNUNET_IDENTITY_ego_get_private_key} or its associated
  4864. public key using @code{GNUNET_IDENTITY_ego_get_public_key}.
  4865. The other operations on egos are pretty straightforward.
  4866. Using @code{GNUNET_IDENTITY_create}, an application can request the
  4867. creation of an ego by specifying the desired name.
  4868. The operation will fail if that name is
  4869. already in use. Using @code{GNUNET_IDENTITY_rename} the name of an
  4870. existing ego can be changed. Finally, egos can be deleted using
  4871. @code{GNUNET_IDENTITY_delete}. All of these operations will trigger
  4872. updates to the callback given to the @code{GNUNET_IDENTITY_connect}
  4873. function of all applications that are connected with the identity service
  4874. at the time. @code{GNUNET_IDENTITY_cancel} can be used to cancel the
  4875. operations before the respective continuations would be called.
  4876. It is not guaranteed that the operation will not be completed anyway,
  4877. only the continuation will no longer be called.
  4878. @node The anonymous Ego
  4879. @subsubsection The anonymous Ego
  4880. A special way to obtain an ego handle is to call
  4881. @code{GNUNET_IDENTITY_ego_get_anonymous}, which returns an ego for the
  4882. "anonymous" user --- anyone knows and can get the private key for this
  4883. user, so it is suitable for operations that are supposed to be anonymous
  4884. but require signatures (for example, to avoid a special path in the code).
  4885. The anonymous ego is always valid and accessing it does not require a
  4886. connection to the identity service.
  4887. @node Convenience API to lookup a single ego
  4888. @subsubsection Convenience API to lookup a single ego
  4889. As applications commonly simply have to lookup a single ego, there is a
  4890. convenience API to do just that. Use @code{GNUNET_IDENTITY_ego_lookup} to
  4891. lookup a single ego by name. Note that this is the user's name for the
  4892. ego, not the service function. The resulting ego will be returned via a
  4893. callback and will only be valid during that callback. The operation can
  4894. be canceled via @code{GNUNET_IDENTITY_ego_lookup_cancel}
  4895. (cancellation is only legal before the callback is invoked).
  4896. @node Associating egos with service functions
  4897. @subsubsection Associating egos with service functions
  4898. The @code{GNUNET_IDENTITY_set} function is used to associate a particular
  4899. ego with a service function. The name used by the service and the ego are
  4900. given as arguments.
  4901. Afterwards, the service can use its name to lookup the associated ego
  4902. using @code{GNUNET_IDENTITY_get}.
  4903. @node The IDENTITY Client-Service Protocol
  4904. @subsection The IDENTITY Client-Service Protocol
  4905. A client connecting to the identity service first sends a message with
  4906. type
  4907. @code{GNUNET_MESSAGE_TYPE_IDENTITY_START} to the service. After that, the
  4908. client will receive information about changes to the egos by receiving
  4909. messages of type @code{GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE}.
  4910. Those messages contain the private key of the ego and the user's name of
  4911. the ego (or zero bytes for the name to indicate that the ego was deleted).
  4912. A special bit @code{end_of_list} is used to indicate the end of the
  4913. initial iteration over the identity service's egos.
  4914. The client can trigger changes to the egos by sending @code{CREATE},
  4915. @code{RENAME} or @code{DELETE} messages.
  4916. The CREATE message contains the private key and the desired name.@
  4917. The RENAME message contains the old name and the new name.@
  4918. The DELETE message only needs to include the name of the ego to delete.@
  4919. The service responds to each of these messages with a @code{RESULT_CODE}
  4920. message which indicates success or error of the operation, and possibly
  4921. a human-readable error message.
  4922. Finally, the client can bind the name of a service function to an ego by
  4923. sending a @code{SET_DEFAULT} message with the name of the service function
  4924. and the private key of the ego.
  4925. Such bindings can then be resolved using a @code{GET_DEFAULT} message,
  4926. which includes the name of the service function. The identity service
  4927. will respond to a GET_DEFAULT request with a SET_DEFAULT message
  4928. containing the respective information, or with a RESULT_CODE to
  4929. indicate an error.
  4930. @cindex NAMESTORE Subsystem
  4931. @node NAMESTORE Subsystem
  4932. @section NAMESTORE Subsystem
  4933. The NAMESTORE subsystem provides persistent storage for local GNS zone
  4934. information. All local GNS zone information are managed by NAMESTORE. It
  4935. provides both the functionality to administer local GNS information (e.g.
  4936. delete and add records) as well as to retrieve GNS information (e.g to
  4937. list name information in a client).
  4938. NAMESTORE does only manage the persistent storage of zone information
  4939. belonging to the user running the service: GNS information from other
  4940. users obtained from the DHT are stored by the NAMECACHE subsystem.
  4941. NAMESTORE uses a plugin-based database backend to store GNS information
  4942. with good performance. Here sqlite, MySQL and PostgreSQL are supported
  4943. database backends.
  4944. NAMESTORE clients interact with the IDENTITY subsystem to obtain
  4945. cryptographic information about zones based on egos as described with the
  4946. IDENTITY subsystem, but internally NAMESTORE refers to zones using the
  4947. ECDSA private key.
  4948. In addition, it collaborates with the NAMECACHE subsystem and
  4949. stores zone information when local information are modified in the
  4950. GNS cache to increase look-up performance for local information.
  4951. NAMESTORE provides functionality to look-up and store records, to iterate
  4952. over a specific or all zones and to monitor zones for changes. NAMESTORE
  4953. functionality can be accessed using the NAMESTORE api or the NAMESTORE
  4954. command line tool.
  4955. @menu
  4956. * libgnunetnamestore::
  4957. @end menu
  4958. @cindex libgnunetnamestore
  4959. @node libgnunetnamestore
  4960. @subsection libgnunetnamestore
  4961. To interact with NAMESTORE clients first connect to the NAMESTORE service
  4962. using the @code{GNUNET_NAMESTORE_connect} passing a configuration handle.
  4963. As a result they obtain a NAMESTORE handle, they can use for operations,
  4964. or NULL is returned if the connection failed.
  4965. To disconnect from NAMESTORE, clients use
  4966. @code{GNUNET_NAMESTORE_disconnect} and specify the handle to disconnect.
  4967. NAMESTORE internally uses the ECDSA private key to refer to zones. These
  4968. private keys can be obtained from the IDENTITY subsytem.
  4969. Here @emph{egos} @emph{can be used to refer to zones or the default ego
  4970. assigned to the GNS subsystem can be used to obtained the master zone's
  4971. private key.}
  4972. @menu
  4973. * Editing Zone Information::
  4974. * Iterating Zone Information::
  4975. * Monitoring Zone Information::
  4976. @end menu
  4977. @node Editing Zone Information
  4978. @subsubsection Editing Zone Information
  4979. NAMESTORE provides functions to lookup records stored under a label in a
  4980. zone and to store records under a label in a zone.
  4981. To store (and delete) records, the client uses the
  4982. @code{GNUNET_NAMESTORE_records_store} function and has to provide
  4983. namestore handle to use, the private key of the zone, the label to store
  4984. the records under, the records and number of records plus an callback
  4985. function.
  4986. After the operation is performed NAMESTORE will call the provided
  4987. callback function with the result GNUNET_SYSERR on failure
  4988. (including timeout/queue drop/failure to validate), GNUNET_NO if content
  4989. was already there or not found GNUNET_YES (or other positive value) on
  4990. success plus an additional error message.
  4991. Records are deleted by using the store command with 0 records to store.
  4992. It is important to note, that records are not merged when records exist
  4993. with the label.
  4994. So a client has first to retrieve records, merge with existing records
  4995. and then store the result.
  4996. To perform a lookup operation, the client uses the
  4997. @code{GNUNET_NAMESTORE_records_store} function. Here it has to pass the
  4998. namestore handle, the private key of the zone and the label. It also has
  4999. to provide a callback function which will be called with the result of
  5000. the lookup operation:
  5001. the zone for the records, the label, and the records including the
  5002. number of records included.
  5003. A special operation is used to set the preferred nickname for a zone.
  5004. This nickname is stored with the zone and is automatically merged with
  5005. all labels and records stored in a zone. Here the client uses the
  5006. @code{GNUNET_NAMESTORE_set_nick} function and passes the private key of
  5007. the zone, the nickname as string plus a the callback with the result of
  5008. the operation.
  5009. @node Iterating Zone Information
  5010. @subsubsection Iterating Zone Information
  5011. A client can iterate over all information in a zone or all zones managed
  5012. by NAMESTORE.
  5013. Here a client uses the @code{GNUNET_NAMESTORE_zone_iteration_start}
  5014. function and passes the namestore handle, the zone to iterate over and a
  5015. callback function to call with the result.
  5016. If the client wants to iterate over all the WHAT!? FIXME, it passes NULL for the zone.
  5017. A @code{GNUNET_NAMESTORE_ZoneIterator} handle is returned to be used to
  5018. continue iteration.
  5019. NAMESTORE calls the callback for every result and expects the client to
  5020. call @code{GNUNET_NAMESTORE_zone_iterator_next} to continue to iterate or
  5021. @code{GNUNET_NAMESTORE_zone_iterator_stop} to interrupt the iteration.
  5022. When NAMESTORE reached the last item it will call the callback with a
  5023. NULL value to indicate.
  5024. @node Monitoring Zone Information
  5025. @subsubsection Monitoring Zone Information
  5026. Clients can also monitor zones to be notified about changes. Here the
  5027. clients uses the @code{GNUNET_NAMESTORE_zone_monitor_start} function and
  5028. passes the private key of the zone and and a callback function to call
  5029. with updates for a zone.
  5030. The client can specify to obtain zone information first by iterating over
  5031. the zone and specify a synchronization callback to be called when the
  5032. client and the namestore are synced.
  5033. On an update, NAMESTORE will call the callback with the private key of the
  5034. zone, the label and the records and their number.
  5035. To stop monitoring, the client calls
  5036. @code{GNUNET_NAMESTORE_zone_monitor_stop} and passes the handle obtained
  5037. from the function to start the monitoring.
  5038. @cindex PEERINFO Subsystem
  5039. @node PEERINFO Subsystem
  5040. @section PEERINFO Subsystem
  5041. The PEERINFO subsystem is used to store verified (validated) information
  5042. about known peers in a persistent way. It obtains these addresses for
  5043. example from TRANSPORT service which is in charge of address validation.
  5044. Validation means that the information in the HELLO message are checked by
  5045. connecting to the addresses and performing a cryptographic handshake to
  5046. authenticate the peer instance stating to be reachable with these
  5047. addresses.
  5048. Peerinfo does not validate the HELLO messages itself but only stores them
  5049. and gives them to interested clients.
  5050. As future work, we think about moving from storing just HELLO messages to
  5051. providing a generic persistent per-peer information store.
  5052. More and more subsystems tend to need to store per-peer information in
  5053. persistent way.
  5054. To not duplicate this functionality we plan to provide a PEERSTORE
  5055. service providing this functionality.
  5056. @menu
  5057. * PEERINFO - Features::
  5058. * PEERINFO - Limitations::
  5059. * DeveloperPeer Information::
  5060. * Startup::
  5061. * Managing Information::
  5062. * Obtaining Information::
  5063. * The PEERINFO Client-Service Protocol::
  5064. * libgnunetpeerinfo::
  5065. @end menu
  5066. @node PEERINFO - Features
  5067. @subsection PEERINFO - Features
  5068. @itemize @bullet
  5069. @item Persistent storage
  5070. @item Client notification mechanism on update
  5071. @item Periodic clean up for expired information
  5072. @item Differentiation between public and friend-only HELLO
  5073. @end itemize
  5074. @node PEERINFO - Limitations
  5075. @subsection PEERINFO - Limitations
  5076. @itemize @bullet
  5077. @item Does not perform HELLO validation
  5078. @end itemize
  5079. @node DeveloperPeer Information
  5080. @subsection DeveloperPeer Information
  5081. The PEERINFO subsystem stores these information in the form of HELLO
  5082. messages you can think of as business cards.
  5083. These HELLO messages contain the public key of a peer and the addresses
  5084. a peer can be reached under.
  5085. The addresses include an expiration date describing how long they are
  5086. valid. This information is updated regularly by the TRANSPORT service by
  5087. revalidating the address.
  5088. If an address is expired and not renewed, it can be removed from the
  5089. HELLO message.
  5090. Some peer do not want to have their HELLO messages distributed to other
  5091. peers, especially when GNUnet's friend-to-friend modus is enabled.
  5092. To prevent this undesired distribution. PEERINFO distinguishes between
  5093. @emph{public} and @emph{friend-only} HELLO messages.
  5094. Public HELLO messages can be freely distributed to other (possibly
  5095. unknown) peers (for example using the hostlist, gossiping, broadcasting),
  5096. whereas friend-only HELLO messages may not be distributed to other peers.
  5097. Friend-only HELLO messages have an additional flag @code{friend_only} set
  5098. internally. For public HELLO message this flag is not set.
  5099. PEERINFO does and cannot not check if a client is allowed to obtain a
  5100. specific HELLO type.
  5101. The HELLO messages can be managed using the GNUnet HELLO library.
  5102. Other GNUnet systems can obtain these information from PEERINFO and use
  5103. it for their purposes.
  5104. Clients are for example the HOSTLIST component providing these
  5105. information to other peers in form of a hostlist or the TRANSPORT
  5106. subsystem using these information to maintain connections to other peers.
  5107. @node Startup
  5108. @subsection Startup
  5109. During startup the PEERINFO services loads persistent HELLOs from disk.
  5110. First PEERINFO parses the directory configured in the HOSTS value of the
  5111. @code{PEERINFO} configuration section to store PEERINFO information.
  5112. For all files found in this directory valid HELLO messages are extracted.
  5113. In addition it loads HELLO messages shipped with the GNUnet distribution.
  5114. These HELLOs are used to simplify network bootstrapping by providing
  5115. valid peer information with the distribution.
  5116. The use of these HELLOs can be prevented by setting the
  5117. @code{USE_INCLUDED_HELLOS} in the @code{PEERINFO} configuration section to
  5118. @code{NO}. Files containing invalid information are removed.
  5119. @node Managing Information
  5120. @subsection Managing Information
  5121. The PEERINFO services stores information about known PEERS and a single
  5122. HELLO message for every peer.
  5123. A peer does not need to have a HELLO if no information are available.
  5124. HELLO information from different sources, for example a HELLO obtained
  5125. from a remote HOSTLIST and a second HELLO stored on disk, are combined
  5126. and merged into one single HELLO message per peer which will be given to
  5127. clients. During this merge process the HELLO is immediately written to
  5128. disk to ensure persistence.
  5129. PEERINFO in addition periodically scans the directory where information
  5130. are stored for empty HELLO messages with expired TRANSPORT addresses.
  5131. This periodic task scans all files in the directory and recreates the
  5132. HELLO messages it finds.
  5133. Expired TRANSPORT addresses are removed from the HELLO and if the
  5134. HELLO does not contain any valid addresses, it is discarded and removed
  5135. from the disk.
  5136. @node Obtaining Information
  5137. @subsection Obtaining Information
  5138. When a client requests information from PEERINFO, PEERINFO performs a
  5139. lookup for the respective peer or all peers if desired and transmits this
  5140. information to the client.
  5141. The client can specify if friend-only HELLOs have to be included or not
  5142. and PEERINFO filters the respective HELLO messages before transmitting
  5143. information.
  5144. To notify clients about changes to PEERINFO information, PEERINFO
  5145. maintains a list of clients interested in this notifications.
  5146. Such a notification occurs if a HELLO for a peer was updated (due to a
  5147. merge for example) or a new peer was added.
  5148. @node The PEERINFO Client-Service Protocol
  5149. @subsection The PEERINFO Client-Service Protocol
  5150. To connect and disconnect to and from the PEERINFO Service PEERINFO
  5151. utilizes the util client/server infrastructure, so no special messages
  5152. types are used here.
  5153. To add information for a peer, the plain HELLO message is transmitted to
  5154. the service without any wrapping. All pieces of information required are
  5155. stored within the HELLO message.
  5156. The PEERINFO service provides a message handler accepting and processing
  5157. these HELLO messages.
  5158. When obtaining PEERINFO information using the iterate functionality
  5159. specific messages are used. To obtain information for all peers, a
  5160. @code{struct ListAllPeersMessage} with message type
  5161. @code{GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL} and a flag
  5162. include_friend_only to indicate if friend-only HELLO messages should be
  5163. included are transmitted. If information for a specific peer is required
  5164. a @code{struct ListAllPeersMessage} with
  5165. @code{GNUNET_MESSAGE_TYPE_PEERINFO_GET} containing the peer identity is
  5166. used.
  5167. For both variants the PEERINFO service replies for each HELLO message it
  5168. wants to transmit with a @code{struct ListAllPeersMessage} with type
  5169. @code{GNUNET_MESSAGE_TYPE_PEERINFO_INFO} containing the plain HELLO.
  5170. The final message is @code{struct GNUNET_MessageHeader} with type
  5171. @code{GNUNET_MESSAGE_TYPE_PEERINFO_INFO}. If the client receives this
  5172. message, it can proceed with the next request if any is pending.
  5173. @node libgnunetpeerinfo
  5174. @subsection libgnunetpeerinfo
  5175. The PEERINFO API consists mainly of three different functionalities:
  5176. @itemize @bullet
  5177. @item maintaining a connection to the service
  5178. @item adding new information to the PEERINFO service
  5179. @item retrieving information from the PEERINFO service
  5180. @end itemize
  5181. @menu
  5182. * Connecting to the PEERINFO Service::
  5183. * Adding Information to the PEERINFO Service::
  5184. * Obtaining Information from the PEERINFO Service::
  5185. @end menu
  5186. @node Connecting to the PEERINFO Service
  5187. @subsubsection Connecting to the PEERINFO Service
  5188. To connect to the PEERINFO service the function
  5189. @code{GNUNET_PEERINFO_connect} is used, taking a configuration handle as
  5190. an argument, and to disconnect from PEERINFO the function
  5191. @code{GNUNET_PEERINFO_disconnect}, taking the PEERINFO
  5192. handle returned from the connect function has to be called.
  5193. @node Adding Information to the PEERINFO Service
  5194. @subsubsection Adding Information to the PEERINFO Service
  5195. @code{GNUNET_PEERINFO_add_peer} adds a new peer to the PEERINFO subsystem
  5196. storage. This function takes the PEERINFO handle as an argument, the HELLO
  5197. message to store and a continuation with a closure to be called with the
  5198. result of the operation.
  5199. The @code{GNUNET_PEERINFO_add_peer} returns a handle to this operation
  5200. allowing to cancel the operation with the respective cancel function
  5201. @code{GNUNET_PEERINFO_add_peer_cancel}. To retrieve information from
  5202. PEERINFO you can iterate over all information stored with PEERINFO or you
  5203. can tell PEERINFO to notify if new peer information are available.
  5204. @node Obtaining Information from the PEERINFO Service
  5205. @subsubsection Obtaining Information from the PEERINFO Service
  5206. To iterate over information in PEERINFO you use
  5207. @code{GNUNET_PEERINFO_iterate}.
  5208. This function expects the PEERINFO handle, a flag if HELLO messages
  5209. intended for friend only mode should be included, a timeout how long the
  5210. operation should take and a callback with a callback closure to be called
  5211. for the results.
  5212. If you want to obtain information for a specific peer, you can specify
  5213. the peer identity, if this identity is NULL, information for all peers are
  5214. returned. The function returns a handle to allow to cancel the operation
  5215. using @code{GNUNET_PEERINFO_iterate_cancel}.
  5216. To get notified when peer information changes, you can use
  5217. @code{GNUNET_PEERINFO_notify}.
  5218. This function expects a configuration handle and a flag if friend-only
  5219. HELLO messages should be included. The PEERINFO service will notify you
  5220. about every change and the callback function will be called to notify you
  5221. about changes. The function returns a handle to cancel notifications
  5222. with @code{GNUNET_PEERINFO_notify_cancel}.
  5223. @cindex PEERSTORE Subsystem
  5224. @node PEERSTORE Subsystem
  5225. @section PEERSTORE Subsystem
  5226. GNUnet's PEERSTORE subsystem offers persistent per-peer storage for other
  5227. GNUnet subsystems. GNUnet subsystems can use PEERSTORE to persistently
  5228. store and retrieve arbitrary data.
  5229. Each data record stored with PEERSTORE contains the following fields:
  5230. @itemize @bullet
  5231. @item subsystem: Name of the subsystem responsible for the record.
  5232. @item peerid: Identity of the peer this record is related to.
  5233. @item key: a key string identifying the record.
  5234. @item value: binary record value.
  5235. @item expiry: record expiry date.
  5236. @end itemize
  5237. @menu
  5238. * Functionality::
  5239. * Architecture::
  5240. * libgnunetpeerstore::
  5241. @end menu
  5242. @node Functionality
  5243. @subsection Functionality
  5244. Subsystems can store any type of value under a (subsystem, peerid, key)
  5245. combination. A "replace" flag set during store operations forces the
  5246. PEERSTORE to replace any old values stored under the same
  5247. (subsystem, peerid, key) combination with the new value.
  5248. Additionally, an expiry date is set after which the record is *possibly*
  5249. deleted by PEERSTORE.
  5250. Subsystems can iterate over all values stored under any of the following
  5251. combination of fields:
  5252. @itemize @bullet
  5253. @item (subsystem)
  5254. @item (subsystem, peerid)
  5255. @item (subsystem, key)
  5256. @item (subsystem, peerid, key)
  5257. @end itemize
  5258. Subsystems can also request to be notified about any new values stored
  5259. under a (subsystem, peerid, key) combination by sending a "watch"
  5260. request to PEERSTORE.
  5261. @node Architecture
  5262. @subsection Architecture
  5263. PEERSTORE implements the following components:
  5264. @itemize @bullet
  5265. @item PEERSTORE service: Handles store, iterate and watch operations.
  5266. @item PEERSTORE API: API to be used by other subsystems to communicate and
  5267. issue commands to the PEERSTORE service.
  5268. @item PEERSTORE plugins: Handles the persistent storage. At the moment,
  5269. only an "sqlite" plugin is implemented.
  5270. @end itemize
  5271. @cindex libgnunetpeerstore
  5272. @node libgnunetpeerstore
  5273. @subsection libgnunetpeerstore
  5274. libgnunetpeerstore is the library containing the PEERSTORE API. Subsystems
  5275. wishing to communicate with the PEERSTORE service use this API to open a
  5276. connection to PEERSTORE. This is done by calling
  5277. @code{GNUNET_PEERSTORE_connect} which returns a handle to the newly
  5278. created connection.
  5279. This handle has to be used with any further calls to the API.
  5280. To store a new record, the function @code{GNUNET_PEERSTORE_store} is to
  5281. be used which requires the record fields and a continuation function that
  5282. will be called by the API after the STORE request is sent to the
  5283. PEERSTORE service.
  5284. Note that calling the continuation function does not mean that the record
  5285. is successfully stored, only that the STORE request has been successfully
  5286. sent to the PEERSTORE service.
  5287. @code{GNUNET_PEERSTORE_store_cancel} can be called to cancel the STORE
  5288. request only before the continuation function has been called.
  5289. To iterate over stored records, the function
  5290. @code{GNUNET_PEERSTORE_iterate} is
  5291. to be used. @emph{peerid} and @emph{key} can be set to NULL. An iterator
  5292. callback function will be called with each matching record found and a
  5293. NULL record at the end to signal the end of result set.
  5294. @code{GNUNET_PEERSTORE_iterate_cancel} can be used to cancel the ITERATE
  5295. request before the iterator callback is called with a NULL record.
  5296. To be notified with new values stored under a (subsystem, peerid, key)
  5297. combination, the function @code{GNUNET_PEERSTORE_watch} is to be used.
  5298. This will register the watcher with the PEERSTORE service, any new
  5299. records matching the given combination will trigger the callback
  5300. function passed to @code{GNUNET_PEERSTORE_watch}. This continues until
  5301. @code{GNUNET_PEERSTORE_watch_cancel} is called or the connection to the
  5302. service is destroyed.
  5303. After the connection is no longer needed, the function
  5304. @code{GNUNET_PEERSTORE_disconnect} can be called to disconnect from the
  5305. PEERSTORE service.
  5306. Any pending ITERATE or WATCH requests will be destroyed.
  5307. If the @code{sync_first} flag is set to @code{GNUNET_YES}, the API will
  5308. delay the disconnection until all pending STORE requests are sent to
  5309. the PEERSTORE service, otherwise, the pending STORE requests will be
  5310. destroyed as well.
  5311. @cindex SET Subsystem
  5312. @node SET Subsystem
  5313. @section SET Subsystem
  5314. The SET subsystem is in process of being replaced by the SETU and
  5315. SETI subsystems, which provide basically the same functionality,
  5316. just using two different subsystems. SETI and SETU should be used
  5317. for new code.
  5318. The SET service implements efficient set operations between two peers
  5319. over a CADET tunnel.
  5320. Currently, set union and set intersection are the only supported
  5321. operations. Elements of a set consist of an @emph{element type} and
  5322. arbitrary binary @emph{data}.
  5323. The size of an element's data is limited to around 62 KB.
  5324. @menu
  5325. * Local Sets::
  5326. * Set Modifications::
  5327. * Set Operations::
  5328. * Result Elements::
  5329. * libgnunetset::
  5330. * The SET Client-Service Protocol::
  5331. * The SET Intersection Peer-to-Peer Protocol::
  5332. * The SET Union Peer-to-Peer Protocol::
  5333. @end menu
  5334. @node Local Sets
  5335. @subsection Local Sets
  5336. Sets created by a local client can be modified and reused for multiple
  5337. operations. As each set operation requires potentially expensive special
  5338. auxiliary data to be computed for each element of a set, a set can only
  5339. participate in one type of set operation (i.e. union or intersection).
  5340. The type of a set is determined upon its creation.
  5341. If a the elements of a set are needed for an operation of a different
  5342. type, all of the set's element must be copied to a new set of appropriate
  5343. type.
  5344. @node Set Modifications
  5345. @subsection Set Modifications
  5346. Even when set operations are active, one can add to and remove elements
  5347. from a set.
  5348. However, these changes will only be visible to operations that have been
  5349. created after the changes have taken place. That is, every set operation
  5350. only sees a snapshot of the set from the time the operation was started.
  5351. This mechanism is @emph{not} implemented by copying the whole set, but by
  5352. attaching @emph{generation information} to each element and operation.
  5353. @node Set Operations
  5354. @subsection Set Operations
  5355. Set operations can be started in two ways: Either by accepting an
  5356. operation request from a remote peer, or by requesting a set operation
  5357. from a remote peer.
  5358. Set operations are uniquely identified by the involved @emph{peers}, an
  5359. @emph{application id} and the @emph{operation type}.
  5360. The client is notified of incoming set operations by @emph{set listeners}.
  5361. A set listener listens for incoming operations of a specific operation
  5362. type and application id.
  5363. Once notified of an incoming set request, the client can accept the set
  5364. request (providing a local set for the operation) or reject it.
  5365. @node Result Elements
  5366. @subsection Result Elements
  5367. The SET service has three @emph{result modes} that determine how an
  5368. operation's result set is delivered to the client:
  5369. @itemize @bullet
  5370. @item @strong{Full Result Set.} All elements of set resulting from the set
  5371. operation are returned to the client.
  5372. @item @strong{Added Elements.} Only elements that result from the
  5373. operation and are not already in the local peer's set are returned.
  5374. Note that for some operations (like set intersection) this result mode
  5375. will never return any elements.
  5376. This can be useful if only the remove peer is actually interested in
  5377. the result of the set operation.
  5378. @item @strong{Removed Elements.} Only elements that are in the local
  5379. peer's initial set but not in the operation's result set are returned.
  5380. Note that for some operations (like set union) this result mode will
  5381. never return any elements. This can be useful if only the remove peer is
  5382. actually interested in the result of the set operation.
  5383. @end itemize
  5384. @cindex libgnunetset
  5385. @node libgnunetset
  5386. @subsection libgnunetset
  5387. @menu
  5388. * Sets::
  5389. * Listeners::
  5390. * Operations::
  5391. * Supplying a Set::
  5392. * The Result Callback::
  5393. @end menu
  5394. @node Sets
  5395. @subsubsection Sets
  5396. New sets are created with @code{GNUNET_SET_create}. Both the local peer's
  5397. configuration (as each set has its own client connection) and the
  5398. operation type must be specified.
  5399. The set exists until either the client calls @code{GNUNET_SET_destroy} or
  5400. the client's connection to the service is disrupted.
  5401. In the latter case, the client is notified by the return value of
  5402. functions dealing with sets. This return value must always be checked.
  5403. Elements are added and removed with @code{GNUNET_SET_add_element} and
  5404. @code{GNUNET_SET_remove_element}.
  5405. @node Listeners
  5406. @subsubsection Listeners
  5407. Listeners are created with @code{GNUNET_SET_listen}. Each time time a
  5408. remote peer suggests a set operation with an application id and operation
  5409. type matching a listener, the listener's callback is invoked.
  5410. The client then must synchronously call either @code{GNUNET_SET_accept}
  5411. or @code{GNUNET_SET_reject}. Note that the operation will not be started
  5412. until the client calls @code{GNUNET_SET_commit}
  5413. (see Section "Supplying a Set").
  5414. @node Operations
  5415. @subsubsection Operations
  5416. Operations to be initiated by the local peer are created with
  5417. @code{GNUNET_SET_prepare}. Note that the operation will not be started
  5418. until the client calls @code{GNUNET_SET_commit}
  5419. (see Section "Supplying a Set").
  5420. @node Supplying a Set
  5421. @subsubsection Supplying a Set
  5422. To create symmetry between the two ways of starting a set operation
  5423. (accepting and initiating it), the operation handles returned by
  5424. @code{GNUNET_SET_accept} and @code{GNUNET_SET_prepare} do not yet have a
  5425. set to operate on, thus they can not do any work yet.
  5426. The client must call @code{GNUNET_SET_commit} to specify a set to use for
  5427. an operation. @code{GNUNET_SET_commit} may only be called once per set
  5428. operation.
  5429. @node The Result Callback
  5430. @subsubsection The Result Callback
  5431. Clients must specify both a result mode and a result callback with
  5432. @code{GNUNET_SET_accept} and @code{GNUNET_SET_prepare}. The result
  5433. callback with a status indicating either that an element was received, or
  5434. the operation failed or succeeded.
  5435. The interpretation of the received element depends on the result mode.
  5436. The callback needs to know which result mode it is used in, as the
  5437. arguments do not indicate if an element is part of the full result set,
  5438. or if it is in the difference between the original set and the final set.
  5439. @node The SET Client-Service Protocol
  5440. @subsection The SET Client-Service Protocol
  5441. @menu
  5442. * Creating Sets::
  5443. * Listeners2::
  5444. * Initiating Operations::
  5445. * Modifying Sets::
  5446. * Results and Operation Status::
  5447. * Iterating Sets::
  5448. @end menu
  5449. @node Creating Sets
  5450. @subsubsection Creating Sets
  5451. For each set of a client, there exists a client connection to the service.
  5452. Sets are created by sending the @code{GNUNET_SERVICE_SET_CREATE} message
  5453. over a new client connection. Multiple operations for one set are
  5454. multiplexed over one client connection, using a request id supplied by
  5455. the client.
  5456. @node Listeners2
  5457. @subsubsection Listeners2
  5458. Each listener also requires a seperate client connection. By sending the
  5459. @code{GNUNET_SERVICE_SET_LISTEN} message, the client notifies the service
  5460. of the application id and operation type it is interested in. A client
  5461. rejects an incoming request by sending @code{GNUNET_SERVICE_SET_REJECT}
  5462. on the listener's client connection.
  5463. In contrast, when accepting an incoming request, a
  5464. @code{GNUNET_SERVICE_SET_ACCEPT} message must be sent over the@ set that
  5465. is supplied for the set operation.
  5466. @node Initiating Operations
  5467. @subsubsection Initiating Operations
  5468. Operations with remote peers are initiated by sending a
  5469. @code{GNUNET_SERVICE_SET_EVALUATE} message to the service. The@ client
  5470. connection that this message is sent by determines the set to use.
  5471. @node Modifying Sets
  5472. @subsubsection Modifying Sets
  5473. Sets are modified with the @code{GNUNET_SERVICE_SET_ADD} and
  5474. @code{GNUNET_SERVICE_SET_REMOVE} messages.
  5475. @c %@menu
  5476. @c %* Results and Operation Status::
  5477. @c %* Iterating Sets::
  5478. @c %@end menu
  5479. @node Results and Operation Status
  5480. @subsubsection Results and Operation Status
  5481. The service notifies the client of result elements and success/failure of
  5482. a set operation with the @code{GNUNET_SERVICE_SET_RESULT} message.
  5483. @node Iterating Sets
  5484. @subsubsection Iterating Sets
  5485. All elements of a set can be requested by sending
  5486. @code{GNUNET_SERVICE_SET_ITER_REQUEST}. The server responds with
  5487. @code{GNUNET_SERVICE_SET_ITER_ELEMENT} and eventually terminates the
  5488. iteration with @code{GNUNET_SERVICE_SET_ITER_DONE}.
  5489. After each received element, the client
  5490. must send @code{GNUNET_SERVICE_SET_ITER_ACK}. Note that only one set
  5491. iteration may be active for a set at any given time.
  5492. @node The SET Intersection Peer-to-Peer Protocol
  5493. @subsection The SET Intersection Peer-to-Peer Protocol
  5494. The intersection protocol operates over CADET and starts with a
  5495. GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST being sent by the peer
  5496. initiating the operation to the peer listening for inbound requests.
  5497. It includes the number of elements of the initiating peer, which is used
  5498. to decide which side will send a Bloom filter first.
  5499. The listening peer checks if the operation type and application
  5500. identifier are acceptable for its current state.
  5501. If not, it responds with a GNUNET_MESSAGE_TYPE_SET_RESULT and a status of
  5502. GNUNET_SET_STATUS_FAILURE (and terminates the CADET channel).
  5503. If the application accepts the request, the listener sends back a
  5504. @code{GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO} if it has
  5505. more elements in the set than the client.
  5506. Otherwise, it immediately starts with the Bloom filter exchange.
  5507. If the initiator receives a
  5508. @code{GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO} response,
  5509. it beings the Bloom filter exchange, unless the set size is indicated to
  5510. be zero, in which case the intersection is considered finished after
  5511. just the initial handshake.
  5512. @menu
  5513. * The Bloom filter exchange::
  5514. * Salt::
  5515. @end menu
  5516. @node The Bloom filter exchange
  5517. @subsubsection The Bloom filter exchange
  5518. In this phase, each peer transmits a Bloom filter over the remaining
  5519. keys of the local set to the other peer using a
  5520. @code{GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF} message. This
  5521. message additionally includes the number of elements left in the sender's
  5522. set, as well as the XOR over all of the keys in that set.
  5523. The number of bits 'k' set per element in the Bloom filter is calculated
  5524. based on the relative size of the two sets.
  5525. Furthermore, the size of the Bloom filter is calculated based on 'k' and
  5526. the number of elements in the set to maximize the amount of data filtered
  5527. per byte transmitted on the wire (while avoiding an excessively high
  5528. number of iterations).
  5529. The receiver of the message removes all elements from its local set that
  5530. do not pass the Bloom filter test.
  5531. It then checks if the set size of the sender and the XOR over the keys
  5532. match what is left of its own set. If they do, it sends a
  5533. @code{GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE} back to indicate
  5534. that the latest set is the final result.
  5535. Otherwise, the receiver starts another Bloom filter exchange, except
  5536. this time as the sender.
  5537. @node Salt
  5538. @subsubsection Salt
  5539. Bloomfilter operations are probabilistic: With some non-zero probability
  5540. the test may incorrectly say an element is in the set, even though it is
  5541. not.
  5542. To mitigate this problem, the intersection protocol iterates exchanging
  5543. Bloom filters using a different random 32-bit salt in each iteration (the
  5544. salt is also included in the message).
  5545. With different salts, set operations may fail for different elements.
  5546. Merging the results from the executions, the probability of failure drops
  5547. to zero.
  5548. The iterations terminate once both peers have established that they have
  5549. sets of the same size, and where the XOR over all keys computes the same
  5550. 512-bit value (leaving a failure probability of 2-511).
  5551. @node The SET Union Peer-to-Peer Protocol
  5552. @subsection The SET Union Peer-to-Peer Protocol
  5553. The SET union protocol is based on Eppstein's efficient set reconciliation
  5554. without prior context. You should read this paper first if you want to
  5555. understand the protocol.
  5556. The union protocol operates over CADET and starts with a
  5557. GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST being sent by the peer
  5558. initiating the operation to the peer listening for inbound requests.
  5559. It includes the number of elements of the initiating peer, which is
  5560. currently not used.
  5561. The listening peer checks if the operation type and application
  5562. identifier are acceptable for its current state. If not, it responds with
  5563. a @code{GNUNET_MESSAGE_TYPE_SET_RESULT} and a status of
  5564. @code{GNUNET_SET_STATUS_FAILURE} (and terminates the CADET channel).
  5565. If the application accepts the request, it sends back a strata estimator
  5566. using a message of type GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE. The
  5567. initiator evaluates the strata estimator and initiates the exchange of
  5568. invertible Bloom filters, sending a GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF.
  5569. During the IBF exchange, if the receiver cannot invert the Bloom filter or
  5570. detects a cycle, it sends a larger IBF in response (up to a defined
  5571. maximum limit; if that limit is reached, the operation fails).
  5572. Elements decoded while processing the IBF are transmitted to the other
  5573. peer using GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, or requested from the
  5574. other peer using GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS messages,
  5575. depending on the sign observed during decoding of the IBF.
  5576. Peers respond to a GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS message
  5577. with the respective element in a GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS
  5578. message. If the IBF fully decodes, the peer responds with a
  5579. GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE message instead of another
  5580. GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF.
  5581. All Bloom filter operations use a salt to mingle keys before hashing them
  5582. into buckets, such that future iterations have a fresh chance of
  5583. succeeding if they failed due to collisions before.
  5584. @cindex SETI Subsystem
  5585. @node SETI Subsystem
  5586. @section SETI Subsystem
  5587. The SET service implements efficient set intersection between two peers
  5588. over a CADET tunnel.
  5589. Elements of a set consist of an @emph{element type} and
  5590. arbitrary binary @emph{data}.
  5591. The size of an element's data is limited to around 62 KB.
  5592. @menu
  5593. * Intersection Sets::
  5594. * Set Intersection Modifications::
  5595. * Set Intersection Operations::
  5596. * Intersection Result Elements::
  5597. * libgnunetseti::
  5598. * The SETI Client-Service Protocol::
  5599. * The SETI Intersection Peer-to-Peer Protocol::
  5600. @end menu
  5601. @node Intersection Sets
  5602. @subsection Intersection Sets
  5603. Sets created by a local client can be modified (by adding additional elements)
  5604. and reused for multiple operations. If elements are to be removed, a fresh
  5605. set must be created by the client.
  5606. @node Set Intersection Modifications
  5607. @subsection Set Intersection Modifications
  5608. Even when set operations are active, one can add elements
  5609. to a set.
  5610. However, these changes will only be visible to operations that have been
  5611. created after the changes have taken place. That is, every set operation
  5612. only sees a snapshot of the set from the time the operation was started.
  5613. This mechanism is @emph{not} implemented by copying the whole set, but by
  5614. attaching @emph{generation information} to each element and operation.
  5615. @node Set Intersection Operations
  5616. @subsection Set Intersection Operations
  5617. Set operations can be started in two ways: Either by accepting an
  5618. operation request from a remote peer, or by requesting a set operation
  5619. from a remote peer.
  5620. Set operations are uniquely identified by the involved @emph{peers}, an
  5621. @emph{application id} and the @emph{operation type}.
  5622. The client is notified of incoming set operations by @emph{set listeners}.
  5623. A set listener listens for incoming operations of a specific operation
  5624. type and application id.
  5625. Once notified of an incoming set request, the client can accept the set
  5626. request (providing a local set for the operation) or reject it.
  5627. @node Intersection Result Elements
  5628. @subsection Intersection Result Elements
  5629. The SET service has two @emph{result modes} that determine how an
  5630. operation's result set is delivered to the client:
  5631. @itemize @bullet
  5632. @item @strong{Return intersection.} All elements of set resulting from the set
  5633. intersection are returned to the client.
  5634. @item @strong{Removed Elements.} Only elements that are in the local
  5635. peer's initial set but not in the intersection are returned.
  5636. @end itemize
  5637. @cindex libgnunetseti
  5638. @node libgnunetseti
  5639. @subsection libgnunetseti
  5640. @menu
  5641. * Intersection Set API::
  5642. * Intersection Listeners::
  5643. * Intersection Operations::
  5644. * Supplying a Set for Intersection::
  5645. * The Intersection Result Callback::
  5646. @end menu
  5647. @node Intersection Set API
  5648. @subsubsection Intersection Set API
  5649. New sets are created with @code{GNUNET_SETI_create}. Only the local peer's
  5650. configuration (as each set has its own client connection) must be provided.
  5651. The set exists until either the client calls @code{GNUNET_SET_destroy} or
  5652. the client's connection to the service is disrupted.
  5653. In the latter case, the client is notified by the return value of
  5654. functions dealing with sets. This return value must always be checked.
  5655. Elements are added with @code{GNUNET_SET_add_element}.
  5656. @node Intersection Listeners
  5657. @subsubsection Intersection Listeners
  5658. Listeners are created with @code{GNUNET_SET_listen}. Each time time a
  5659. remote peer suggests a set operation with an application id and operation
  5660. type matching a listener, the listener's callback is invoked.
  5661. The client then must synchronously call either @code{GNUNET_SET_accept}
  5662. or @code{GNUNET_SET_reject}. Note that the operation will not be started
  5663. until the client calls @code{GNUNET_SET_commit}
  5664. (see Section "Supplying a Set").
  5665. @node Intersection Operations
  5666. @subsubsection Intersection Operations
  5667. Operations to be initiated by the local peer are created with
  5668. @code{GNUNET_SET_prepare}. Note that the operation will not be started
  5669. until the client calls @code{GNUNET_SET_commit}
  5670. (see Section "Supplying a Set").
  5671. @node Supplying a Set for Intersection
  5672. @subsubsection Supplying a Set for Intersection
  5673. To create symmetry between the two ways of starting a set operation
  5674. (accepting and initiating it), the operation handles returned by
  5675. @code{GNUNET_SET_accept} and @code{GNUNET_SET_prepare} do not yet have a
  5676. set to operate on, thus they can not do any work yet.
  5677. The client must call @code{GNUNET_SET_commit} to specify a set to use for
  5678. an operation. @code{GNUNET_SET_commit} may only be called once per set
  5679. operation.
  5680. @node The Intersection Result Callback
  5681. @subsubsection The Intersection Result Callback
  5682. Clients must specify both a result mode and a result callback with
  5683. @code{GNUNET_SET_accept} and @code{GNUNET_SET_prepare}. The result
  5684. callback with a status indicating either that an element was received, or
  5685. the operation failed or succeeded.
  5686. The interpretation of the received element depends on the result mode.
  5687. The callback needs to know which result mode it is used in, as the
  5688. arguments do not indicate if an element is part of the full result set,
  5689. or if it is in the difference between the original set and the final set.
  5690. @node The SETI Client-Service Protocol
  5691. @subsection The SETI Client-Service Protocol
  5692. @menu
  5693. * Creating Intersection Sets::
  5694. * Listeners for Intersection::
  5695. * Initiating Intersection Operations::
  5696. * Modifying Intersection Sets::
  5697. * Intersection Results and Operation Status::
  5698. @end menu
  5699. @node Creating Intersection Sets
  5700. @subsubsection Creating Intersection Sets
  5701. For each set of a client, there exists a client connection to the service.
  5702. Sets are created by sending the @code{GNUNET_SERVICE_SETI_CREATE} message
  5703. over a new client connection. Multiple operations for one set are
  5704. multiplexed over one client connection, using a request id supplied by
  5705. the client.
  5706. @node Listeners for Intersection
  5707. @subsubsection Listeners for Intersection
  5708. Each listener also requires a seperate client connection. By sending the
  5709. @code{GNUNET_SERVICE_SETI_LISTEN} message, the client notifies the service
  5710. of the application id and operation type it is interested in. A client
  5711. rejects an incoming request by sending @code{GNUNET_SERVICE_SETI_REJECT}
  5712. on the listener's client connection.
  5713. In contrast, when accepting an incoming request, a
  5714. @code{GNUNET_SERVICE_SETI_ACCEPT} message must be sent over the@ set that
  5715. is supplied for the set operation.
  5716. @node Initiating Intersection Operations
  5717. @subsubsection Initiating Intersection Operations
  5718. Operations with remote peers are initiated by sending a
  5719. @code{GNUNET_SERVICE_SETI_EVALUATE} message to the service. The@ client
  5720. connection that this message is sent by determines the set to use.
  5721. @node Modifying Intersection Sets
  5722. @subsubsection Modifying Intersection Sets
  5723. Sets are modified with the @code{GNUNET_SERVICE_SETI_ADD} message.
  5724. @c %@menu
  5725. @c %* Results and Operation Status::
  5726. @c %* Iterating Sets::
  5727. @c %@end menu
  5728. @node Intersection Results and Operation Status
  5729. @subsubsection Intersection Results and Operation Status
  5730. The service notifies the client of result elements and success/failure of
  5731. a set operation with the @code{GNUNET_SERVICE_SETI_RESULT} message.
  5732. @node The SETI Intersection Peer-to-Peer Protocol
  5733. @subsection The SETI Intersection Peer-to-Peer Protocol
  5734. The intersection protocol operates over CADET and starts with a
  5735. GNUNET_MESSAGE_TYPE_SETI_P2P_OPERATION_REQUEST being sent by the peer
  5736. initiating the operation to the peer listening for inbound requests.
  5737. It includes the number of elements of the initiating peer, which is used
  5738. to decide which side will send a Bloom filter first.
  5739. The listening peer checks if the operation type and application
  5740. identifier are acceptable for its current state.
  5741. If not, it responds with a GNUNET_MESSAGE_TYPE_SETI_RESULT and a status of
  5742. GNUNET_SETI_STATUS_FAILURE (and terminates the CADET channel).
  5743. If the application accepts the request, the listener sends back a
  5744. @code{GNUNET_MESSAGE_TYPE_SETI_P2P_ELEMENT_INFO} if it has
  5745. more elements in the set than the client.
  5746. Otherwise, it immediately starts with the Bloom filter exchange.
  5747. If the initiator receives a
  5748. @code{GNUNET_MESSAGE_TYPE_SETI_P2P_ELEMENT_INFO} response,
  5749. it beings the Bloom filter exchange, unless the set size is indicated to
  5750. be zero, in which case the intersection is considered finished after
  5751. just the initial handshake.
  5752. @menu
  5753. * The Bloom filter exchange in SETI::
  5754. * Intersection Salt::
  5755. @end menu
  5756. @node The Bloom filter exchange in SETI
  5757. @subsubsection The Bloom filter exchange in SETI
  5758. In this phase, each peer transmits a Bloom filter over the remaining
  5759. keys of the local set to the other peer using a
  5760. @code{GNUNET_MESSAGE_TYPE_SETI_P2P_BF} message. This
  5761. message additionally includes the number of elements left in the sender's
  5762. set, as well as the XOR over all of the keys in that set.
  5763. The number of bits 'k' set per element in the Bloom filter is calculated
  5764. based on the relative size of the two sets.
  5765. Furthermore, the size of the Bloom filter is calculated based on 'k' and
  5766. the number of elements in the set to maximize the amount of data filtered
  5767. per byte transmitted on the wire (while avoiding an excessively high
  5768. number of iterations).
  5769. The receiver of the message removes all elements from its local set that
  5770. do not pass the Bloom filter test.
  5771. It then checks if the set size of the sender and the XOR over the keys
  5772. match what is left of its own set. If they do, it sends a
  5773. @code{GNUNET_MESSAGE_TYPE_SETI_P2P_DONE} back to indicate
  5774. that the latest set is the final result.
  5775. Otherwise, the receiver starts another Bloom filter exchange, except
  5776. this time as the sender.
  5777. @node Intersection Salt
  5778. @subsubsection Intersection Salt
  5779. Bloom filter operations are probabilistic: With some non-zero probability
  5780. the test may incorrectly say an element is in the set, even though it is
  5781. not.
  5782. To mitigate this problem, the intersection protocol iterates exchanging
  5783. Bloom filters using a different random 32-bit salt in each iteration (the
  5784. salt is also included in the message).
  5785. With different salts, set operations may fail for different elements.
  5786. Merging the results from the executions, the probability of failure drops
  5787. to zero.
  5788. The iterations terminate once both peers have established that they have
  5789. sets of the same size, and where the XOR over all keys computes the same
  5790. 512-bit value (leaving a failure probability of 2-511).
  5791. @cindex SETU Subsystem
  5792. @node SETU Subsystem
  5793. @section SETU Subsystem
  5794. The SETU service implements efficient set union operations between two peers
  5795. over a CADET tunnel. Elements of a set consist of an @emph{element type} and
  5796. arbitrary binary @emph{data}. The size of an element's data is limited to
  5797. around 62 KB.
  5798. @menu
  5799. * Union Sets::
  5800. * Set Union Modifications::
  5801. * Set Union Operations::
  5802. * Union Result Elements::
  5803. * libgnunetsetu::
  5804. * The SETU Client-Service Protocol::
  5805. * The SETU Union Peer-to-Peer Protocol::
  5806. @end menu
  5807. @node Union Sets
  5808. @subsection Union Sets
  5809. Sets created by a local client can be modified (by adding additional elements)
  5810. and reused for multiple operations. If elements are to be removed, a fresh
  5811. set must be created by the client.
  5812. @node Set Union Modifications
  5813. @subsection Set Union Modifications
  5814. Even when set operations are active, one can add elements
  5815. to a set.
  5816. However, these changes will only be visible to operations that have been
  5817. created after the changes have taken place. That is, every set operation
  5818. only sees a snapshot of the set from the time the operation was started.
  5819. This mechanism is @emph{not} implemented by copying the whole set, but by
  5820. attaching @emph{generation information} to each element and operation.
  5821. @node Set Union Operations
  5822. @subsection Set Union Operations
  5823. Set operations can be started in two ways: Either by accepting an
  5824. operation request from a remote peer, or by requesting a set operation
  5825. from a remote peer.
  5826. Set operations are uniquely identified by the involved @emph{peers}, an
  5827. @emph{application id} and the @emph{operation type}.
  5828. The client is notified of incoming set operations by @emph{set listeners}.
  5829. A set listener listens for incoming operations of a specific operation
  5830. type and application id.
  5831. Once notified of an incoming set request, the client can accept the set
  5832. request (providing a local set for the operation) or reject it.
  5833. @node Union Result Elements
  5834. @subsection Union Result Elements
  5835. The SET service has three @emph{result modes} that determine how an
  5836. operation's result set is delivered to the client:
  5837. @itemize @bullet
  5838. @item @strong{Locally added Elements.} Elements that are in the union
  5839. but not already in the local peer's set are returned.
  5840. @item @strong{Remote added Elements.} Additionally, notify the client
  5841. if the remote peer lacked some elements and thus also return to the
  5842. local client those elements that we are sending to the remote peer to
  5843. be added to its union. Obtaining these elements requires setting
  5844. the @code{GNUNET_SETU_OPTION_SYMMETRIC} option.
  5845. @end itemize
  5846. @cindex libgnunetsetu
  5847. @node libgnunetsetu
  5848. @subsection libgnunetsetu
  5849. @menu
  5850. * Union Set API::
  5851. * Union Listeners::
  5852. * Union Operations::
  5853. * Supplying a Set for Union::
  5854. * The Union Result Callback::
  5855. @end menu
  5856. @node Union Set API
  5857. @subsubsection Union Set API
  5858. New sets are created with @code{GNUNET_SETU_create}. Only the local peer's
  5859. configuration (as each set has its own client connection) must be provided.
  5860. The set exists until either the client calls @code{GNUNET_SETU_destroy} or
  5861. the client's connection to the service is disrupted.
  5862. In the latter case, the client is notified by the return value of
  5863. functions dealing with sets. This return value must always be checked.
  5864. Elements are added with @code{GNUNET_SETU_add_element}.
  5865. @node Union Listeners
  5866. @subsubsection Union Listeners
  5867. Listeners are created with @code{GNUNET_SETU_listen}. Each time time a
  5868. remote peer suggests a set operation with an application id and operation
  5869. type matching a listener, the listener's callback is invoked.
  5870. The client then must synchronously call either @code{GNUNET_SETU_accept}
  5871. or @code{GNUNET_SETU_reject}. Note that the operation will not be started
  5872. until the client calls @code{GNUNET_SETU_commit}
  5873. (see Section "Supplying a Set").
  5874. @node Union Operations
  5875. @subsubsection Union Operations
  5876. Operations to be initiated by the local peer are created with
  5877. @code{GNUNET_SETU_prepare}. Note that the operation will not be started
  5878. until the client calls @code{GNUNET_SETU_commit}
  5879. (see Section "Supplying a Set").
  5880. @node Supplying a Set for Union
  5881. @subsubsection Supplying a Set for Union
  5882. To create symmetry between the two ways of starting a set operation
  5883. (accepting and initiating it), the operation handles returned by
  5884. @code{GNUNET_SETU_accept} and @code{GNUNET_SETU_prepare} do not yet have a
  5885. set to operate on, thus they can not do any work yet.
  5886. The client must call @code{GNUNET_SETU_commit} to specify a set to use for
  5887. an operation. @code{GNUNET_SETU_commit} may only be called once per set
  5888. operation.
  5889. @node The Union Result Callback
  5890. @subsubsection The Union Result Callback
  5891. Clients must specify both a result mode and a result callback with
  5892. @code{GNUNET_SETU_accept} and @code{GNUNET_SETU_prepare}. The result
  5893. callback with a status indicating either that an element was received,
  5894. transmitted to the other peer (if this information was requested), or
  5895. if the operation failed or ultimately succeeded.
  5896. @node The SETU Client-Service Protocol
  5897. @subsection The SETU Client-Service Protocol
  5898. @menu
  5899. * Creating Union Sets::
  5900. * Listeners for Union::
  5901. * Initiating Union Operations::
  5902. * Modifying Union Sets::
  5903. * Union Results and Operation Status::
  5904. @end menu
  5905. @node Creating Union Sets
  5906. @subsubsection Creating Union Sets
  5907. For each set of a client, there exists a client connection to the service.
  5908. Sets are created by sending the @code{GNUNET_SERVICE_SETU_CREATE} message
  5909. over a new client connection. Multiple operations for one set are
  5910. multiplexed over one client connection, using a request id supplied by
  5911. the client.
  5912. @node Listeners for Union
  5913. @subsubsection Listeners for Union
  5914. Each listener also requires a seperate client connection. By sending the
  5915. @code{GNUNET_SERVICE_SETU_LISTEN} message, the client notifies the service
  5916. of the application id and operation type it is interested in. A client
  5917. rejects an incoming request by sending @code{GNUNET_SERVICE_SETU_REJECT}
  5918. on the listener's client connection.
  5919. In contrast, when accepting an incoming request, a
  5920. @code{GNUNET_SERVICE_SETU_ACCEPT} message must be sent over the@ set that
  5921. is supplied for the set operation.
  5922. @node Initiating Union Operations
  5923. @subsubsection Initiating Union Operations
  5924. Operations with remote peers are initiated by sending a
  5925. @code{GNUNET_SERVICE_SETU_EVALUATE} message to the service. The@ client
  5926. connection that this message is sent by determines the set to use.
  5927. @node Modifying Union Sets
  5928. @subsubsection Modifying Union Sets
  5929. Sets are modified with the @code{GNUNET_SERVICE_SETU_ADD} message.
  5930. @c %@menu
  5931. @c %* Results and Operation Status::
  5932. @c %* Iterating Sets::
  5933. @c %@end menu
  5934. @node Union Results and Operation Status
  5935. @subsubsection Union Results and Operation Status
  5936. The service notifies the client of result elements and success/failure of
  5937. a set operation with the @code{GNUNET_SERVICE_SETU_RESULT} message.
  5938. @node The SETU Union Peer-to-Peer Protocol
  5939. @subsection The SETU Union Peer-to-Peer Protocol
  5940. The SET union protocol is based on Eppstein's efficient set reconciliation
  5941. without prior context. You should read this paper first if you want to
  5942. understand the protocol.
  5943. The union protocol operates over CADET and starts with a
  5944. GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST being sent by the peer
  5945. initiating the operation to the peer listening for inbound requests.
  5946. It includes the number of elements of the initiating peer, which is
  5947. currently not used.
  5948. The listening peer checks if the operation type and application
  5949. identifier are acceptable for its current state. If not, it responds with
  5950. a @code{GNUNET_MESSAGE_TYPE_SETU_RESULT} and a status of
  5951. @code{GNUNET_SETU_STATUS_FAILURE} (and terminates the CADET channel).
  5952. If the application accepts the request, it sends back a strata estimator
  5953. using a message of type GNUNET_MESSAGE_TYPE_SETU_P2P_SE. The
  5954. initiator evaluates the strata estimator and initiates the exchange of
  5955. invertible Bloom filters, sending a GNUNET_MESSAGE_TYPE_SETU_P2P_IBF.
  5956. During the IBF exchange, if the receiver cannot invert the Bloom filter or
  5957. detects a cycle, it sends a larger IBF in response (up to a defined
  5958. maximum limit; if that limit is reached, the operation fails).
  5959. Elements decoded while processing the IBF are transmitted to the other
  5960. peer using GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS, or requested from the
  5961. other peer using GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENT_REQUESTS messages,
  5962. depending on the sign observed during decoding of the IBF.
  5963. Peers respond to a GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENT_REQUESTS message
  5964. with the respective element in a GNUNET_MESSAGE_TYPE_SETU_P2P_ELEMENTS
  5965. message. If the IBF fully decodes, the peer responds with a
  5966. GNUNET_MESSAGE_TYPE_SETU_P2P_DONE message instead of another
  5967. GNUNET_MESSAGE_TYPE_SETU_P2P_IBF.
  5968. All Bloom filter operations use a salt to mingle keys before hashing them
  5969. into buckets, such that future iterations have a fresh chance of
  5970. succeeding if they failed due to collisions before.
  5971. @cindex STATISTICS Subsystem
  5972. @node STATISTICS Subsystem
  5973. @section STATISTICS Subsystem
  5974. In GNUnet, the STATISTICS subsystem offers a central place for all
  5975. subsystems to publish unsigned 64-bit integer run-time statistics.
  5976. Keeping this information centrally means that there is a unified way for
  5977. the user to obtain data on all subsystems, and individual subsystems do
  5978. not have to always include a custom data export method for performance
  5979. metrics and other statistics. For example, the TRANSPORT system uses
  5980. STATISTICS to update information about the number of directly connected
  5981. peers and the bandwidth that has been consumed by the various plugins.
  5982. This information is valuable for diagnosing connectivity and performance
  5983. issues.
  5984. Following the GNUnet service architecture, the STATISTICS subsystem is
  5985. divided into an API which is exposed through the header
  5986. @strong{gnunet_statistics_service.h} and the STATISTICS service
  5987. @strong{gnunet-service-statistics}. The @strong{gnunet-statistics}
  5988. command-line tool can be used to obtain (and change) information about
  5989. the values stored by the STATISTICS service. The STATISTICS service does
  5990. not communicate with other peers.
  5991. Data is stored in the STATISTICS service in the form of tuples
  5992. @strong{(subsystem, name, value, persistence)}. The subsystem determines
  5993. to which other GNUnet's subsystem the data belongs. name is the name
  5994. through which value is associated. It uniquely identifies the record
  5995. from among other records belonging to the same subsystem.
  5996. In some parts of the code, the pair @strong{(subsystem, name)} is called
  5997. a @strong{statistic} as it identifies the values stored in the STATISTCS
  5998. service.The persistence flag determines if the record has to be preserved
  5999. across service restarts. A record is said to be persistent if this flag
  6000. is set for it; if not, the record is treated as a non-persistent record
  6001. and it is lost after service restart. Persistent records are written to
  6002. and read from the file @strong{statistics.data} before shutdown
  6003. and upon startup. The file is located in the HOME directory of the peer.
  6004. An anomaly of the STATISTICS service is that it does not terminate
  6005. immediately upon receiving a shutdown signal if it has any clients
  6006. connected to it. It waits for all the clients that are not monitors to
  6007. close their connections before terminating itself.
  6008. This is to prevent the loss of data during peer shutdown --- delaying the
  6009. STATISTICS service shutdown helps other services to store important data
  6010. to STATISTICS during shutdown.
  6011. @menu
  6012. * libgnunetstatistics::
  6013. * The STATISTICS Client-Service Protocol::
  6014. @end menu
  6015. @cindex libgnunetstatistics
  6016. @node libgnunetstatistics
  6017. @subsection libgnunetstatistics
  6018. @strong{libgnunetstatistics} is the library containing the API for the
  6019. STATISTICS subsystem. Any process requiring to use STATISTICS should use
  6020. this API by to open a connection to the STATISTICS service.
  6021. This is done by calling the function @code{GNUNET_STATISTICS_create()}.
  6022. This function takes the subsystem's name which is trying to use STATISTICS
  6023. and a configuration.
  6024. All values written to STATISTICS with this connection will be placed in
  6025. the section corresponding to the given subsystem's name.
  6026. The connection to STATISTICS can be destroyed with the function
  6027. @code{GNUNET_STATISTICS_destroy()}. This function allows for the
  6028. connection to be destroyed immediately or upon transferring all
  6029. pending write requests to the service.
  6030. Note: STATISTICS subsystem can be disabled by setting @code{DISABLE = YES}
  6031. under the @code{[STATISTICS]} section in the configuration. With such a
  6032. configuration all calls to @code{GNUNET_STATISTICS_create()} return
  6033. @code{NULL} as the STATISTICS subsystem is unavailable and no other
  6034. functions from the API can be used.
  6035. @menu
  6036. * Statistics retrieval::
  6037. * Setting statistics and updating them::
  6038. * Watches::
  6039. @end menu
  6040. @node Statistics retrieval
  6041. @subsubsection Statistics retrieval
  6042. Once a connection to the statistics service is obtained, information
  6043. about any other system which uses statistics can be retrieved with the
  6044. function GNUNET_STATISTICS_get().
  6045. This function takes the connection handle, the name of the subsystem
  6046. whose information we are interested in (a @code{NULL} value will
  6047. retrieve information of all available subsystems using STATISTICS), the
  6048. name of the statistic we are interested in (a @code{NULL} value will
  6049. retrieve all available statistics), a continuation callback which is
  6050. called when all of requested information is retrieved, an iterator
  6051. callback which is called for each parameter in the retrieved information
  6052. and a closure for the aforementioned callbacks. The library then invokes
  6053. the iterator callback for each value matching the request.
  6054. Call to @code{GNUNET_STATISTICS_get()} is asynchronous and can be
  6055. canceled with the function @code{GNUNET_STATISTICS_get_cancel()}.
  6056. This is helpful when retrieving statistics takes too long and especially
  6057. when we want to shutdown and cleanup everything.
  6058. @node Setting statistics and updating them
  6059. @subsubsection Setting statistics and updating them
  6060. So far we have seen how to retrieve statistics, here we will learn how we
  6061. can set statistics and update them so that other subsystems can retrieve
  6062. them.
  6063. A new statistic can be set using the function
  6064. @code{GNUNET_STATISTICS_set()}.
  6065. This function takes the name of the statistic and its value and a flag to
  6066. make the statistic persistent.
  6067. The value of the statistic should be of the type @code{uint64_t}.
  6068. The function does not take the name of the subsystem; it is determined
  6069. from the previous @code{GNUNET_STATISTICS_create()} invocation. If
  6070. the given statistic is already present, its value is overwritten.
  6071. An existing statistics can be updated, i.e its value can be increased or
  6072. decreased by an amount with the function
  6073. @code{GNUNET_STATISTICS_update()}.
  6074. The parameters to this function are similar to
  6075. @code{GNUNET_STATISTICS_set()}, except that it takes the amount to be
  6076. changed as a type @code{int64_t} instead of the value.
  6077. The library will combine multiple set or update operations into one
  6078. message if the client performs requests at a rate that is faster than the
  6079. available IPC with the STATISTICS service. Thus, the client does not have
  6080. to worry about sending requests too quickly.
  6081. @node Watches
  6082. @subsubsection Watches
  6083. As interesting feature of STATISTICS lies in serving notifications
  6084. whenever a statistic of our interest is modified.
  6085. This is achieved by registering a watch through the function
  6086. @code{GNUNET_STATISTICS_watch()}.
  6087. The parameters of this function are similar to those of
  6088. @code{GNUNET_STATISTICS_get()}.
  6089. Changes to the respective statistic's value will then cause the given
  6090. iterator callback to be called.
  6091. Note: A watch can only be registered for a specific statistic. Hence
  6092. the subsystem name and the parameter name cannot be @code{NULL} in a
  6093. call to @code{GNUNET_STATISTICS_watch()}.
  6094. A registered watch will keep notifying any value changes until
  6095. @code{GNUNET_STATISTICS_watch_cancel()} is called with the same
  6096. parameters that are used for registering the watch.
  6097. @node The STATISTICS Client-Service Protocol
  6098. @subsection The STATISTICS Client-Service Protocol
  6099. @menu
  6100. * Statistics retrieval2::
  6101. * Setting and updating statistics::
  6102. * Watching for updates::
  6103. @end menu
  6104. @node Statistics retrieval2
  6105. @subsubsection Statistics retrieval2
  6106. To retrieve statistics, the client transmits a message of type
  6107. @code{GNUNET_MESSAGE_TYPE_STATISTICS_GET} containing the given subsystem
  6108. name and statistic parameter to the STATISTICS service.
  6109. The service responds with a message of type
  6110. @code{GNUNET_MESSAGE_TYPE_STATISTICS_VALUE} for each of the statistics
  6111. parameters that match the client request for the client. The end of
  6112. information retrieved is signaled by the service by sending a message of
  6113. type @code{GNUNET_MESSAGE_TYPE_STATISTICS_END}.
  6114. @node Setting and updating statistics
  6115. @subsubsection Setting and updating statistics
  6116. The subsystem name, parameter name, its value and the persistence flag are
  6117. communicated to the service through the message
  6118. @code{GNUNET_MESSAGE_TYPE_STATISTICS_SET}.
  6119. When the service receives a message of type
  6120. @code{GNUNET_MESSAGE_TYPE_STATISTICS_SET}, it retrieves the subsystem
  6121. name and checks for a statistic parameter with matching the name given in
  6122. the message.
  6123. If a statistic parameter is found, the value is overwritten by the new
  6124. value from the message; if not found then a new statistic parameter is
  6125. created with the given name and value.
  6126. In addition to just setting an absolute value, it is possible to perform a
  6127. relative update by sending a message of type
  6128. @code{GNUNET_MESSAGE_TYPE_STATISTICS_SET} with an update flag
  6129. (@code{GNUNET_STATISTICS_SETFLAG_RELATIVE}) signifying that the value in
  6130. the message should be treated as an update value.
  6131. @node Watching for updates
  6132. @subsubsection Watching for updates
  6133. The function registers the watch at the service by sending a message of
  6134. type @code{GNUNET_MESSAGE_TYPE_STATISTICS_WATCH}. The service then sends
  6135. notifications through messages of type
  6136. @code{GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE} whenever the statistic
  6137. parameter's value is changed.
  6138. @cindex DHT
  6139. @cindex Distributed Hash Table
  6140. @node Distributed Hash Table (DHT)
  6141. @section Distributed Hash Table (DHT)
  6142. GNUnet includes a generic distributed hash table that can be used by
  6143. developers building P2P applications in the framework.
  6144. This section documents high-level features and how developers are
  6145. expected to use the DHT.
  6146. We have a research paper detailing how the DHT works.
  6147. Also, Nate's thesis includes a detailed description and performance
  6148. analysis (in chapter 6).
  6149. Key features of GNUnet's DHT include:
  6150. @itemize @bullet
  6151. @item stores key-value pairs with values up to (approximately) 63k in size
  6152. @item works with many underlay network topologies (small-world, random
  6153. graph), underlay does not need to be a full mesh / clique
  6154. @item support for extended queries (more than just a simple 'key'),
  6155. filtering duplicate replies within the network (bloomfilter) and content
  6156. validation (for details, please read the subsection on the block library)
  6157. @item can (optionally) return paths taken by the PUT and GET operations
  6158. to the application
  6159. @item provides content replication to handle churn
  6160. @end itemize
  6161. GNUnet's DHT is randomized and unreliable. Unreliable means that there is
  6162. no strict guarantee that a value stored in the DHT is always
  6163. found --- values are only found with high probability.
  6164. While this is somewhat true in all P2P DHTs, GNUnet developers should be
  6165. particularly wary of this fact (this will help you write secure,
  6166. fault-tolerant code). Thus, when writing any application using the DHT,
  6167. you should always consider the possibility that a value stored in the
  6168. DHT by you or some other peer might simply not be returned, or returned
  6169. with a significant delay.
  6170. Your application logic must be written to tolerate this (naturally, some
  6171. loss of performance or quality of service is expected in this case).
  6172. @menu
  6173. * Block library and plugins::
  6174. * libgnunetdht::
  6175. * The DHT Client-Service Protocol::
  6176. * The DHT Peer-to-Peer Protocol::
  6177. @end menu
  6178. @node Block library and plugins
  6179. @subsection Block library and plugins
  6180. @menu
  6181. * What is a Block?::
  6182. * The API of libgnunetblock::
  6183. * Queries::
  6184. * Sample Code::
  6185. * Conclusion2::
  6186. @end menu
  6187. @node What is a Block?
  6188. @subsubsection What is a Block?
  6189. Blocks are small (< 63k) pieces of data stored under a key (struct
  6190. GNUNET_HashCode). Blocks have a type (enum GNUNET_BlockType) which defines
  6191. their data format. Blocks are used in GNUnet as units of static data
  6192. exchanged between peers and stored (or cached) locally.
  6193. Uses of blocks include file-sharing (the files are broken up into blocks),
  6194. the VPN (DNS information is stored in blocks) and the DHT (all
  6195. information in the DHT and meta-information for the maintenance of the
  6196. DHT are both stored using blocks).
  6197. The block subsystem provides a few common functions that must be
  6198. available for any type of block.
  6199. @cindex libgnunetblock API
  6200. @node The API of libgnunetblock
  6201. @subsubsection The API of libgnunetblock
  6202. The block library requires for each (family of) block type(s) a block
  6203. plugin (implementing @file{gnunet_block_plugin.h}) that provides basic
  6204. functions that are needed by the DHT (and possibly other subsystems) to
  6205. manage the block.
  6206. These block plugins are typically implemented within their respective
  6207. subsystems.
  6208. The main block library is then used to locate, load and query the
  6209. appropriate block plugin.
  6210. Which plugin is appropriate is determined by the block type (which is
  6211. just a 32-bit integer). Block plugins contain code that specifies which
  6212. block types are supported by a given plugin. The block library loads all
  6213. block plugins that are installed at the local peer and forwards the
  6214. application request to the respective plugin.
  6215. The central functions of the block APIs (plugin and main library) are to
  6216. allow the mapping of blocks to their respective key (if possible) and the
  6217. ability to check that a block is well-formed and matches a given
  6218. request (again, if possible).
  6219. This way, GNUnet can avoid storing invalid blocks, storing blocks under
  6220. the wrong key and forwarding blocks in response to a query that they do
  6221. not answer.
  6222. One key function of block plugins is that it allows GNUnet to detect
  6223. duplicate replies (via the Bloom filter). All plugins MUST support
  6224. detecting duplicate replies (by adding the current response to the
  6225. Bloom filter and rejecting it if it is encountered again).
  6226. If a plugin fails to do this, responses may loop in the network.
  6227. @node Queries
  6228. @subsubsection Queries
  6229. The query format for any block in GNUnet consists of four main components.
  6230. First, the type of the desired block must be specified. Second, the query
  6231. must contain a hash code. The hash code is used for lookups in hash
  6232. tables and databases and must not be unique for the block (however, if
  6233. possible a unique hash should be used as this would be best for
  6234. performance).
  6235. Third, an optional Bloom filter can be specified to exclude known results;
  6236. replies that hash to the bits set in the Bloom filter are considered
  6237. invalid. False-positives can be eliminated by sending the same query
  6238. again with a different Bloom filter mutator value, which parameterizes
  6239. the hash function that is used.
  6240. Finally, an optional application-specific "eXtended query" (xquery) can
  6241. be specified to further constrain the results. It is entirely up to
  6242. the type-specific plugin to determine whether or not a given block
  6243. matches a query (type, hash, Bloom filter, and xquery).
  6244. Naturally, not all xquery's are valid and some types of blocks may not
  6245. support Bloom filters either, so the plugin also needs to check if the
  6246. query is valid in the first place.
  6247. Depending on the results from the plugin, the DHT will then discard the
  6248. (invalid) query, forward the query, discard the (invalid) reply, cache the
  6249. (valid) reply, and/or forward the (valid and non-duplicate) reply.
  6250. @node Sample Code
  6251. @subsubsection Sample Code
  6252. The source code in @strong{plugin_block_test.c} is a good starting point
  6253. for new block plugins --- it does the minimal work by implementing a
  6254. plugin that performs no validation at all.
  6255. The respective @strong{Makefile.am} shows how to build and install a
  6256. block plugin.
  6257. @node Conclusion2
  6258. @subsubsection Conclusion2
  6259. In conclusion, GNUnet subsystems that want to use the DHT need to define a
  6260. block format and write a plugin to match queries and replies. For testing,
  6261. the @code{GNUNET_BLOCK_TYPE_TEST} block type can be used; it accepts
  6262. any query as valid and any reply as matching any query.
  6263. This type is also used for the DHT command line tools.
  6264. However, it should NOT be used for normal applications due to the lack
  6265. of error checking that results from this primitive implementation.
  6266. @cindex libgnunetdht
  6267. @node libgnunetdht
  6268. @subsection libgnunetdht
  6269. The DHT API itself is pretty simple and offers the usual GET and PUT
  6270. functions that work as expected. The specified block type refers to the
  6271. block library which allows the DHT to run application-specific logic for
  6272. data stored in the network.
  6273. @menu
  6274. * GET::
  6275. * PUT::
  6276. * MONITOR::
  6277. * DHT Routing Options::
  6278. @end menu
  6279. @node GET
  6280. @subsubsection GET
  6281. When using GET, the main consideration for developers (other than the
  6282. block library) should be that after issuing a GET, the DHT will
  6283. continuously cause (small amounts of) network traffic until the operation
  6284. is explicitly canceled.
  6285. So GET does not simply send out a single network request once; instead,
  6286. the DHT will continue to search for data. This is needed to achieve good
  6287. success rates and also handles the case where the respective PUT
  6288. operation happens after the GET operation was started.
  6289. Developers should not cancel an existing GET operation and then
  6290. explicitly re-start it to trigger a new round of network requests;
  6291. this is simply inefficient, especially as the internal automated version
  6292. can be more efficient, for example by filtering results in the network
  6293. that have already been returned.
  6294. If an application that performs a GET request has a set of replies that it
  6295. already knows and would like to filter, it can call@
  6296. @code{GNUNET_DHT_get_filter_known_results} with an array of hashes over
  6297. the respective blocks to tell the DHT that these results are not
  6298. desired (any more).
  6299. This way, the DHT will filter the respective blocks using the block
  6300. library in the network, which may result in a significant reduction in
  6301. bandwidth consumption.
  6302. @node PUT
  6303. @subsubsection PUT
  6304. @c inconsistent use of ``must'' above it's written ``MUST''
  6305. In contrast to GET operations, developers @strong{must} manually re-run
  6306. PUT operations periodically (if they intend the content to continue to be
  6307. available). Content stored in the DHT expires or might be lost due to
  6308. churn.
  6309. Furthermore, GNUnet's DHT typically requires multiple rounds of PUT
  6310. operations before a key-value pair is consistently available to all
  6311. peers (the DHT randomizes paths and thus storage locations, and only
  6312. after multiple rounds of PUTs there will be a sufficient number of
  6313. replicas in large DHTs). An explicit PUT operation using the DHT API will
  6314. only cause network traffic once, so in order to ensure basic availability
  6315. and resistance to churn (and adversaries), PUTs must be repeated.
  6316. While the exact frequency depends on the application, a rule of thumb is
  6317. that there should be at least a dozen PUT operations within the content
  6318. lifetime. Content in the DHT typically expires after one day, so
  6319. DHT PUT operations should be repeated at least every 1-2 hours.
  6320. @node MONITOR
  6321. @subsubsection MONITOR
  6322. The DHT API also allows applications to monitor messages crossing the
  6323. local DHT service.
  6324. The types of messages used by the DHT are GET, PUT and RESULT messages.
  6325. Using the monitoring API, applications can choose to monitor these
  6326. requests, possibly limiting themselves to requests for a particular block
  6327. type.
  6328. The monitoring API is not only useful for diagnostics, it can also be
  6329. used to trigger application operations based on PUT operations.
  6330. For example, an application may use PUTs to distribute work requests to
  6331. other peers.
  6332. The workers would then monitor for PUTs that give them work, instead of
  6333. looking for work using GET operations.
  6334. This can be beneficial, especially if the workers have no good way to
  6335. guess the keys under which work would be stored.
  6336. Naturally, additional protocols might be needed to ensure that the desired
  6337. number of workers will process the distributed workload.
  6338. @node DHT Routing Options
  6339. @subsubsection DHT Routing Options
  6340. There are two important options for GET and PUT requests:
  6341. @table @asis
  6342. @item GNUNET_DHT_RO_DEMULITPLEX_EVERYWHERE This option means that all
  6343. peers should process the request, even if their peer ID is not closest to
  6344. the key. For a PUT request, this means that all peers that a request
  6345. traverses may make a copy of the data.
  6346. Similarly for a GET request, all peers will check their local database
  6347. for a result. Setting this option can thus significantly improve caching
  6348. and reduce bandwidth consumption --- at the expense of a larger DHT
  6349. database. If in doubt, we recommend that this option should be used.
  6350. @item GNUNET_DHT_RO_RECORD_ROUTE This option instructs the DHT to record
  6351. the path that a GET or a PUT request is taking through the overlay
  6352. network. The resulting paths are then returned to the application with
  6353. the respective result. This allows the receiver of a result to construct
  6354. a path to the originator of the data, which might then be used for
  6355. routing. Naturally, setting this option requires additional bandwidth
  6356. and disk space, so applications should only set this if the paths are
  6357. needed by the application logic.
  6358. @item GNUNET_DHT_RO_FIND_PEER This option is an internal option used by
  6359. the DHT's peer discovery mechanism and should not be used by applications.
  6360. @item GNUNET_DHT_RO_BART This option is currently not implemented. It may
  6361. in the future offer performance improvements for clique topologies.
  6362. @end table
  6363. @node The DHT Client-Service Protocol
  6364. @subsection The DHT Client-Service Protocol
  6365. @menu
  6366. * PUTting data into the DHT::
  6367. * GETting data from the DHT::
  6368. * Monitoring the DHT::
  6369. @end menu
  6370. @node PUTting data into the DHT
  6371. @subsubsection PUTting data into the DHT
  6372. To store (PUT) data into the DHT, the client sends a
  6373. @code{struct GNUNET_DHT_ClientPutMessage} to the service.
  6374. This message specifies the block type, routing options, the desired
  6375. replication level, the expiration time, key,
  6376. value and a 64-bit unique ID for the operation. The service responds with
  6377. a @code{struct GNUNET_DHT_ClientPutConfirmationMessage} with the same
  6378. 64-bit unique ID. Note that the service sends the confirmation as soon as
  6379. it has locally processed the PUT request. The PUT may still be
  6380. propagating through the network at this time.
  6381. In the future, we may want to change this to provide (limited) feedback
  6382. to the client, for example if we detect that the PUT operation had no
  6383. effect because the same key-value pair was already stored in the DHT.
  6384. However, changing this would also require additional state and messages
  6385. in the P2P interaction.
  6386. @node GETting data from the DHT
  6387. @subsubsection GETting data from the DHT
  6388. To retrieve (GET) data from the DHT, the client sends a
  6389. @code{struct GNUNET_DHT_ClientGetMessage} to the service. The message
  6390. specifies routing options, a replication level (for replicating the GET,
  6391. not the content), the desired block type, the key, the (optional)
  6392. extended query and unique 64-bit request ID.
  6393. Additionally, the client may send any number of
  6394. @code{struct GNUNET_DHT_ClientGetResultSeenMessage}s to notify the
  6395. service about results that the client is already aware of.
  6396. These messages consist of the key, the unique 64-bit ID of the request,
  6397. and an arbitrary number of hash codes over the blocks that the client is
  6398. already aware of. As messages are restricted to 64k, a client that
  6399. already knows more than about a thousand blocks may need to send
  6400. several of these messages. Naturally, the client should transmit these
  6401. messages as quickly as possible after the original GET request such that
  6402. the DHT can filter those results in the network early on. Naturally, as
  6403. these messages are sent after the original request, it is conceivable
  6404. that the DHT service may return blocks that match those already known
  6405. to the client anyway.
  6406. In response to a GET request, the service will send @code{struct
  6407. GNUNET_DHT_ClientResultMessage}s to the client. These messages contain the
  6408. block type, expiration, key, unique ID of the request and of course the
  6409. value (a block). Depending on the options set for the respective
  6410. operations, the replies may also contain the path the GET and/or the PUT
  6411. took through the network.
  6412. A client can stop receiving replies either by disconnecting or by sending
  6413. a @code{struct GNUNET_DHT_ClientGetStopMessage} which must contain the
  6414. key and the 64-bit unique ID of the original request. Using an
  6415. explicit "stop" message is more common as this allows a client to run
  6416. many concurrent GET operations over the same connection with the DHT
  6417. service --- and to stop them individually.
  6418. @node Monitoring the DHT
  6419. @subsubsection Monitoring the DHT
  6420. To begin monitoring, the client sends a
  6421. @code{struct GNUNET_DHT_MonitorStartStop} message to the DHT service.
  6422. In this message, flags can be set to enable (or disable) monitoring of
  6423. GET, PUT and RESULT messages that pass through a peer. The message can
  6424. also restrict monitoring to a particular block type or a particular key.
  6425. Once monitoring is enabled, the DHT service will notify the client about
  6426. any matching event using @code{struct GNUNET_DHT_MonitorGetMessage}s for
  6427. GET events, @code{struct GNUNET_DHT_MonitorPutMessage} for PUT events
  6428. and @code{struct GNUNET_DHT_MonitorGetRespMessage} for RESULTs. Each of
  6429. these messages contains all of the information about the event.
  6430. @node The DHT Peer-to-Peer Protocol
  6431. @subsection The DHT Peer-to-Peer Protocol
  6432. @menu
  6433. * Routing GETs or PUTs::
  6434. * PUTting data into the DHT2::
  6435. * GETting data from the DHT2::
  6436. @end menu
  6437. @node Routing GETs or PUTs
  6438. @subsubsection Routing GETs or PUTs
  6439. When routing GETs or PUTs, the DHT service selects a suitable subset of
  6440. neighbours for forwarding. The exact number of neighbours can be zero or
  6441. more and depends on the hop counter of the query (initially zero) in
  6442. relation to the (log of) the network size estimate, the desired
  6443. replication level and the peer's connectivity.
  6444. Depending on the hop counter and our network size estimate, the selection
  6445. of the peers maybe randomized or by proximity to the key.
  6446. Furthermore, requests include a set of peers that a request has already
  6447. traversed; those peers are also excluded from the selection.
  6448. @node PUTting data into the DHT2
  6449. @subsubsection PUTting data into the DHT2
  6450. To PUT data into the DHT, the service sends a @code{struct PeerPutMessage}
  6451. of type @code{GNUNET_MESSAGE_TYPE_DHT_P2P_PUT} to the respective
  6452. neighbour.
  6453. In addition to the usual information about the content (type, routing
  6454. options, desired replication level for the content, expiration time, key
  6455. and value), the message contains a fixed-size Bloom filter with
  6456. information about which peers (may) have already seen this request.
  6457. This Bloom filter is used to ensure that DHT messages never loop back to
  6458. a peer that has already processed the request.
  6459. Additionally, the message includes the current hop counter and, depending
  6460. on the routing options, the message may include the full path that the
  6461. message has taken so far.
  6462. The Bloom filter should already contain the identity of the previous hop;
  6463. however, the path should not include the identity of the previous hop and
  6464. the receiver should append the identity of the sender to the path, not
  6465. its own identity (this is done to reduce bandwidth).
  6466. @node GETting data from the DHT2
  6467. @subsubsection GETting data from the DHT2
  6468. A peer can search the DHT by sending @code{struct PeerGetMessage}s of type
  6469. @code{GNUNET_MESSAGE_TYPE_DHT_P2P_GET} to other peers. In addition to the
  6470. usual information about the request (type, routing options, desired
  6471. replication level for the request, the key and the extended query), a GET
  6472. request also contains a hop counter, a Bloom filter over the peers
  6473. that have processed the request already and depending on the routing
  6474. options the full path traversed by the GET.
  6475. Finally, a GET request includes a variable-size second Bloom filter and a
  6476. so-called Bloom filter mutator value which together indicate which
  6477. replies the sender has already seen. During the lookup, each block that
  6478. matches they block type, key and extended query is additionally subjected
  6479. to a test against this Bloom filter.
  6480. The block plugin is expected to take the hash of the block and combine it
  6481. with the mutator value and check if the result is not yet in the Bloom
  6482. filter. The originator of the query will from time to time modify the
  6483. mutator to (eventually) allow false-positives filtered by the Bloom filter
  6484. to be returned.
  6485. Peers that receive a GET request perform a local lookup (depending on
  6486. their proximity to the key and the query options) and forward the request
  6487. to other peers.
  6488. They then remember the request (including the Bloom filter for blocking
  6489. duplicate results) and when they obtain a matching, non-filtered response
  6490. a @code{struct PeerResultMessage} of type
  6491. @code{GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT} is forwarded to the previous
  6492. hop.
  6493. Whenever a result is forwarded, the block plugin is used to update the
  6494. Bloom filter accordingly, to ensure that the same result is never
  6495. forwarded more than once.
  6496. The DHT service may also cache forwarded results locally if the
  6497. "CACHE_RESULTS" option is set to "YES" in the configuration.
  6498. @cindex GNS
  6499. @cindex GNU Name System
  6500. @node GNU Name System (GNS)
  6501. @section GNU Name System (GNS)
  6502. The GNU Name System (GNS) is a decentralized database that enables users
  6503. to securely resolve names to values.
  6504. Names can be used to identify other users (for example, in social
  6505. networking), or network services (for example, VPN services running at a
  6506. peer in GNUnet, or purely IP-based services on the Internet).
  6507. Users interact with GNS by typing in a hostname that ends in a
  6508. top-level domain that is configured in the ``GNS'' section, matches
  6509. an identity of the user or ends in a Base32-encoded public key.
  6510. Videos giving an overview of most of the GNS and the motivations behind
  6511. it is available here and here.
  6512. The remainder of this chapter targets developers that are familiar with
  6513. high level concepts of GNS as presented in these talks.
  6514. @c TODO: Add links to here and here and to these.
  6515. GNS-aware applications should use the GNS resolver to obtain the
  6516. respective records that are stored under that name in GNS.
  6517. Each record consists of a type, value, expiration time and flags.
  6518. The type specifies the format of the value. Types below 65536 correspond
  6519. to DNS record types, larger values are used for GNS-specific records.
  6520. Applications can define new GNS record types by reserving a number and
  6521. implementing a plugin (which mostly needs to convert the binary value
  6522. representation to a human-readable text format and vice-versa).
  6523. The expiration time specifies how long the record is to be valid.
  6524. The GNS API ensures that applications are only given non-expired values.
  6525. The flags are typically irrelevant for applications, as GNS uses them
  6526. internally to control visibility and validity of records.
  6527. Records are stored along with a signature.
  6528. The signature is generated using the private key of the authoritative
  6529. zone. This allows any GNS resolver to verify the correctness of a
  6530. name-value mapping.
  6531. Internally, GNS uses the NAMECACHE to cache information obtained from
  6532. other users, the NAMESTORE to store information specific to the local
  6533. users, and the DHT to exchange data between users.
  6534. A plugin API is used to enable applications to define new GNS
  6535. record types.
  6536. @menu
  6537. * libgnunetgns::
  6538. * libgnunetgnsrecord::
  6539. * GNS plugins::
  6540. * The GNS Client-Service Protocol::
  6541. * Hijacking the DNS-Traffic using gnunet-service-dns::
  6542. @c * Serving DNS lookups via GNS on W32::
  6543. * Importing DNS Zones into GNS::
  6544. @end menu
  6545. @node libgnunetgns
  6546. @subsection libgnunetgns
  6547. The GNS API itself is extremely simple. Clients first connect to the
  6548. GNS service using @code{GNUNET_GNS_connect}.
  6549. They can then perform lookups using @code{GNUNET_GNS_lookup} or cancel
  6550. pending lookups using @code{GNUNET_GNS_lookup_cancel}.
  6551. Once finished, clients disconnect using @code{GNUNET_GNS_disconnect}.
  6552. @menu
  6553. * Looking up records::
  6554. * Accessing the records::
  6555. * Creating records::
  6556. * Future work::
  6557. @end menu
  6558. @node Looking up records
  6559. @subsubsection Looking up records
  6560. @code{GNUNET_GNS_lookup} takes a number of arguments:
  6561. @table @asis
  6562. @item handle This is simply the GNS connection handle from
  6563. @code{GNUNET_GNS_connect}.
  6564. @item name The client needs to specify the name to
  6565. be resolved. This can be any valid DNS or GNS hostname.
  6566. @item zone The client
  6567. needs to specify the public key of the GNS zone against which the
  6568. resolution should be done.
  6569. Note that a key must be provided, the client should
  6570. look up plausible values using its configuration,
  6571. the identity service and by attempting to interpret the
  6572. TLD as a base32-encoded public key.
  6573. @item type This is the desired GNS or DNS record type
  6574. to look for. While all records for the given name will be returned, this
  6575. can be important if the client wants to resolve record types that
  6576. themselves delegate resolution, such as CNAME, PKEY or GNS2DNS.
  6577. Resolving a record of any of these types will only work if the respective
  6578. record type is specified in the request, as the GNS resolver will
  6579. otherwise follow the delegation and return the records from the
  6580. respective destination, instead of the delegating record.
  6581. @item only_cached This argument should typically be set to
  6582. @code{GNUNET_NO}. Setting it to @code{GNUNET_YES} disables resolution via
  6583. the overlay network.
  6584. @item shorten_zone_key If GNS encounters new names during resolution,
  6585. their respective zones can automatically be learned and added to the
  6586. "shorten zone". If this is desired, clients must pass the private key of
  6587. the shorten zone. If NULL is passed, shortening is disabled.
  6588. @item proc This argument identifies
  6589. the function to call with the result. It is given proc_cls, the number of
  6590. records found (possibly zero) and the array of the records as arguments.
  6591. proc will only be called once. After proc,> has been called, the lookup
  6592. must no longer be canceled.
  6593. @item proc_cls The closure for proc.
  6594. @end table
  6595. @node Accessing the records
  6596. @subsubsection Accessing the records
  6597. The @code{libgnunetgnsrecord} library provides an API to manipulate the
  6598. GNS record array that is given to proc. In particular, it offers
  6599. functions such as converting record values to human-readable
  6600. strings (and back). However, most @code{libgnunetgnsrecord} functions are
  6601. not interesting to GNS client applications.
  6602. For DNS records, the @code{libgnunetdnsparser} library provides
  6603. functions for parsing (and serializing) common types of DNS records.
  6604. @node Creating records
  6605. @subsubsection Creating records
  6606. Creating GNS records is typically done by building the respective record
  6607. information (possibly with the help of @code{libgnunetgnsrecord} and
  6608. @code{libgnunetdnsparser}) and then using the @code{libgnunetnamestore} to
  6609. publish the information. The GNS API is not involved in this
  6610. operation.
  6611. @node Future work
  6612. @subsubsection Future work
  6613. In the future, we want to expand @code{libgnunetgns} to allow
  6614. applications to observe shortening operations performed during GNS
  6615. resolution, for example so that users can receive visual feedback when
  6616. this happens.
  6617. @node libgnunetgnsrecord
  6618. @subsection libgnunetgnsrecord
  6619. The @code{libgnunetgnsrecord} library is used to manipulate GNS
  6620. records (in plaintext or in their encrypted format).
  6621. Applications mostly interact with @code{libgnunetgnsrecord} by using the
  6622. functions to convert GNS record values to strings or vice-versa, or to
  6623. lookup a GNS record type number by name (or vice-versa).
  6624. The library also provides various other functions that are mostly
  6625. used internally within GNS, such as converting keys to names, checking for
  6626. expiration, encrypting GNS records to GNS blocks, verifying GNS block
  6627. signatures and decrypting GNS records from GNS blocks.
  6628. We will now discuss the four commonly used functions of the API.@
  6629. @code{libgnunetgnsrecord} does not perform these operations itself,
  6630. but instead uses plugins to perform the operation.
  6631. GNUnet includes plugins to support common DNS record types as well as
  6632. standard GNS record types.
  6633. @menu
  6634. * Value handling::
  6635. * Type handling::
  6636. @end menu
  6637. @node Value handling
  6638. @subsubsection Value handling
  6639. @code{GNUNET_GNSRECORD_value_to_string} can be used to convert
  6640. the (binary) representation of a GNS record value to a human readable,
  6641. 0-terminated UTF-8 string.
  6642. NULL is returned if the specified record type is not supported by any
  6643. available plugin.
  6644. @code{GNUNET_GNSRECORD_string_to_value} can be used to try to convert a
  6645. human readable string to the respective (binary) representation of
  6646. a GNS record value.
  6647. @node Type handling
  6648. @subsubsection Type handling
  6649. @code{GNUNET_GNSRECORD_typename_to_number} can be used to obtain the
  6650. numeric value associated with a given typename. For example, given the
  6651. typename "A" (for DNS A reocrds), the function will return the number 1.
  6652. A list of common DNS record types is
  6653. @uref{http://en.wikipedia.org/wiki/List_of_DNS_record_types, here}.
  6654. Note that not all DNS record types are supported by GNUnet GNSRECORD
  6655. plugins at this time.
  6656. @code{GNUNET_GNSRECORD_number_to_typename} can be used to obtain the
  6657. typename associated with a given numeric value.
  6658. For example, given the type number 1, the function will return the
  6659. typename "A".
  6660. @node GNS plugins
  6661. @subsection GNS plugins
  6662. Adding a new GNS record type typically involves writing (or extending) a
  6663. GNSRECORD plugin. The plugin needs to implement the
  6664. @code{gnunet_gnsrecord_plugin.h} API which provides basic functions that
  6665. are needed by GNSRECORD to convert typenames and values of the respective
  6666. record type to strings (and back).
  6667. These gnsrecord plugins are typically implemented within their respective
  6668. subsystems.
  6669. Examples for such plugins can be found in the GNSRECORD, GNS and
  6670. CONVERSATION subsystems.
  6671. The @code{libgnunetgnsrecord} library is then used to locate, load and
  6672. query the appropriate gnsrecord plugin.
  6673. Which plugin is appropriate is determined by the record type (which is
  6674. just a 32-bit integer). The @code{libgnunetgnsrecord} library loads all
  6675. block plugins that are installed at the local peer and forwards the
  6676. application request to the plugins. If the record type is not
  6677. supported by the plugin, it should simply return an error code.
  6678. The central functions of the block APIs (plugin and main library) are the
  6679. same four functions for converting between values and strings, and
  6680. typenames and numbers documented in the previous subsection.
  6681. @node The GNS Client-Service Protocol
  6682. @subsection The GNS Client-Service Protocol
  6683. The GNS client-service protocol consists of two simple messages, the
  6684. @code{LOOKUP} message and the @code{LOOKUP_RESULT}. Each @code{LOOKUP}
  6685. message contains a unique 32-bit identifier, which will be included in the
  6686. corresponding response. Thus, clients can send many lookup requests in
  6687. parallel and receive responses out-of-order.
  6688. A @code{LOOKUP} request also includes the public key of the GNS zone,
  6689. the desired record type and fields specifying whether shortening is
  6690. enabled or networking is disabled. Finally, the @code{LOOKUP} message
  6691. includes the name to be resolved.
  6692. The response includes the number of records and the records themselves
  6693. in the format created by @code{GNUNET_GNSRECORD_records_serialize}.
  6694. They can thus be deserialized using
  6695. @code{GNUNET_GNSRECORD_records_deserialize}.
  6696. @node Hijacking the DNS-Traffic using gnunet-service-dns
  6697. @subsection Hijacking the DNS-Traffic using gnunet-service-dns
  6698. This section documents how the gnunet-service-dns (and the
  6699. gnunet-helper-dns) intercepts DNS queries from the local system.
  6700. This is merely one method for how we can obtain GNS queries.
  6701. It is also possible to change @code{resolv.conf} to point to a machine
  6702. running @code{gnunet-dns2gns} or to modify libc's name system switch
  6703. (NSS) configuration to include a GNS resolution plugin.
  6704. The method described in this chapter is more of a last-ditch catch-all
  6705. approach.
  6706. @code{gnunet-service-dns} enables intercepting DNS traffic using policy
  6707. based routing.
  6708. We MARK every outgoing DNS-packet if it was not sent by our application.
  6709. Using a second routing table in the Linux kernel these marked packets are
  6710. then routed through our virtual network interface and can thus be
  6711. captured unchanged.
  6712. Our application then reads the query and decides how to handle it.
  6713. If the query can be addressed via GNS, it is passed to
  6714. @code{gnunet-service-gns} and resolved internally using GNS.
  6715. In the future, a reverse query for an address of the configured virtual
  6716. network could be answered with records kept about previous forward
  6717. queries.
  6718. Queries that are not hijacked by some application using the DNS service
  6719. will be sent to the original recipient.
  6720. The answer to the query will always be sent back through the virtual
  6721. interface with the original nameserver as source address.
  6722. @menu
  6723. * Network Setup Details::
  6724. @end menu
  6725. @node Network Setup Details
  6726. @subsubsection Network Setup Details
  6727. The DNS interceptor adds the following rules to the Linux kernel:
  6728. @example
  6729. iptables -t mangle -I OUTPUT 1 -p udp --sport $LOCALPORT --dport 53 \
  6730. -j ACCEPT iptables -t mangle -I OUTPUT 2 -p udp --dport 53 -j MARK \
  6731. --set-mark 3 ip rule add fwmark 3 table2 ip route add default via \
  6732. $VIRTUALDNS table2
  6733. @end example
  6734. @c FIXME: Rewrite to reflect display which is no longer content by line
  6735. @c FIXME: due to the < 74 characters limit.
  6736. Line 1 makes sure that all packets coming from a port our application
  6737. opened beforehand (@code{$LOCALPORT}) will be routed normally.
  6738. Line 2 marks every other packet to a DNS-Server with mark 3 (chosen
  6739. arbitrarily). The third line adds a routing policy based on this mark
  6740. 3 via the routing table.
  6741. @c @node Serving DNS lookups via GNS on W32
  6742. @c @subsection Serving DNS lookups via GNS on W32
  6743. @c This section documents how the libw32nsp (and
  6744. @c gnunet-gns-helper-service-w32) do DNS resolutions of DNS queries on the
  6745. @c local system. This only applies to GNUnet running on W32.
  6746. @c W32 has a concept of "Namespaces" and "Namespace providers".
  6747. @c These are used to present various name systems to applications in a
  6748. @c generic way.
  6749. @c Namespaces include DNS, mDNS, NLA and others. For each namespace any
  6750. @c number of providers could be registered, and they are queried in an order
  6751. @c of priority (which is adjustable).
  6752. @c Applications can resolve names by using WSALookupService*() family of
  6753. @c functions.
  6754. @c However, these are WSA-only facilities. Common BSD socket functions for
  6755. @c namespace resolutions are gethostbyname and getaddrinfo (among others).
  6756. @c These functions are implemented internally (by default - by mswsock,
  6757. @c which also implements the default DNS provider) as wrappers around
  6758. @c WSALookupService*() functions (see "Sample Code for a Service Provider"
  6759. @c on MSDN).
  6760. @c On W32 GNUnet builds a libw32nsp - a namespace provider, which can then be
  6761. @c installed into the system by using w32nsp-install (and uninstalled by
  6762. @c w32nsp-uninstall), as described in "Installation Handbook".
  6763. @c libw32nsp is very simple and has almost no dependencies. As a response to
  6764. @c NSPLookupServiceBegin(), it only checks that the provider GUID passed to
  6765. @c it by the caller matches GNUnet DNS Provider GUID,
  6766. @c then connects to
  6767. @c gnunet-gns-helper-service-w32 at 127.0.0.1:5353 (hardcoded) and sends the
  6768. @c name resolution request there, returning the connected socket to the
  6769. @c caller.
  6770. @c When the caller invokes NSPLookupServiceNext(), libw32nsp reads a
  6771. @c completely formed reply from that socket, unmarshalls it, then gives
  6772. @c it back to the caller.
  6773. @c At the moment gnunet-gns-helper-service-w32 is implemented to ever give
  6774. @c only one reply, and subsequent calls to NSPLookupServiceNext() will fail
  6775. @c with WSA_NODATA (first call to NSPLookupServiceNext() might also fail if
  6776. @c GNS failed to find the name, or there was an error connecting to it).
  6777. @c gnunet-gns-helper-service-w32 does most of the processing:
  6778. @c @itemize @bullet
  6779. @c @item Maintains a connection to GNS.
  6780. @c @item Reads GNS config and loads appropriate keys.
  6781. @c @item Checks service GUID and decides on the type of record to look up,
  6782. @c refusing to make a lookup outright when unsupported service GUID is
  6783. @c passed.
  6784. @c @item Launches the lookup
  6785. @c @end itemize
  6786. @c When lookup result arrives, gnunet-gns-helper-service-w32 forms a complete
  6787. @c reply (including filling a WSAQUERYSETW structure and, possibly, a binary
  6788. @c blob with a hostent structure for gethostbyname() client), marshalls it,
  6789. @c and sends it back to libw32nsp. If no records were found, it sends an
  6790. @c empty header.
  6791. @c This works for most normal applications that use gethostbyname() or
  6792. @c getaddrinfo() to resolve names, but fails to do anything with
  6793. @c applications that use alternative means of resolving names (such as
  6794. @c sending queries to a DNS server directly by themselves).
  6795. @c This includes some of well known utilities, like "ping" and "nslookup".
  6796. @node Importing DNS Zones into GNS
  6797. @subsection Importing DNS Zones into GNS
  6798. This section discusses the challenges and problems faced when writing the
  6799. Ascension tool. It also takes a look at possible improvements in the
  6800. future.
  6801. Consider the following diagram that shows the workflow of Ascension:
  6802. @image{images/ascension_ssd,6in,,Ascensions workflow}
  6803. Further the interaction between components of GNUnet are shown in the diagram
  6804. below:
  6805. @center @image{images/ascension_interaction,,6in,Ascensions workflow}
  6806. @menu
  6807. * Conversions between DNS and GNS::
  6808. * DNS Zone Size::
  6809. * Performance::
  6810. @end menu
  6811. @cindex DNS Conversion
  6812. @node Conversions between DNS and GNS
  6813. @subsubsection Conversions between DNS and GNS
  6814. The differences between the two name systems lies in the details and is not
  6815. always transparent. For instance an SRV record is converted to a BOX record
  6816. which is unique to GNS.
  6817. This is done by converting to a BOX record from an existing SRV record:
  6818. @example
  6819. # SRV
  6820. # _service._proto.name. TTL class SRV priority weight port target
  6821. _sip._tcp.example.com. 14000 IN SRV 0 0 5060 www.example.com.
  6822. # BOX
  6823. # TTL BOX flags port protocol recordtype priority weight port target
  6824. 14000 BOX n 5060 6 33 0 0 5060 www.example.com
  6825. @end example
  6826. Other records that need to undergo such transformation is the MX record type,
  6827. as well as the SOA record type.
  6828. Transformation of a SOA record into GNS works as described in the
  6829. following example. Very important to note are the rname and mname keys.
  6830. @example
  6831. # BIND syntax for a clean SOA record
  6832. @ IN SOA master.example.com. hostmaster.example.com. (
  6833. 2017030300 ; serial
  6834. 3600 ; refresh
  6835. 1800 ; retry
  6836. 604800 ; expire
  6837. 600 ) ; ttl
  6838. # Recordline for adding the record
  6839. $ gnunet-namestore -z example.com -a -n @ -t SOA -V \
  6840. rname=master.example.com mname=hostmaster.example.com \
  6841. 2017030300,3600,1800,604800,600 -e 7200s
  6842. @end example
  6843. The transformation of MX records is done in a simple way.
  6844. @example
  6845. # mail.example.com. 3600 IN MX 10 mail.example.com.
  6846. $ gnunet-namestore -z example.com -n mail -R 3600 MX n 10,mail
  6847. @end example
  6848. Finally, one of the biggest struggling points were the NS records that are
  6849. found in top level domain zones. The intended behaviour for those is to add
  6850. GNS2DNS records for those so that gnunet-gns can resolve records for those
  6851. domains on its own. Those require the values from DNS GLUE records, provided
  6852. they are within the same zone.
  6853. The following two examples show one record with a GLUE record and the other one
  6854. does not have a GLUE record. This takes place in the 'com' TLD.
  6855. @example
  6856. # ns1.example.com 86400 IN A 127.0.0.1
  6857. # example.com 86400 IN NS ns1.example.com.
  6858. $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \
  6859. example.com@@127.0.0.1
  6860. # example.com 86400 IN NS ns1.example.org.
  6861. $ gnunet-namestore -z com -n example -R 86400 GNS2DNS n \
  6862. example.com@@ns1.example.org
  6863. @end example
  6864. As you can see, one of the GNS2DNS records has an IP address listed and the
  6865. other one a DNS name. For the first one there is a GLUE record to do the
  6866. translation directly and the second one will issue another DNS query to figure
  6867. out the IP of ns1.example.org.
  6868. A solution was found by creating a hierarchical zone structure in GNS and linking
  6869. the zones using PKEY records to one another. This allows the resolution of the
  6870. name servers to work within GNS while not taking control over unwanted zones.
  6871. Currently the following record types are supported:
  6872. @itemize @bullet
  6873. @item A
  6874. @item AAAA
  6875. @item CNAME
  6876. @item MX
  6877. @item NS
  6878. @item SRV
  6879. @item TXT
  6880. @end itemize
  6881. This is not due to technical limitations but rather a practical ones. The
  6882. problem occurs with DNSSEC enabled DNS zones. As records within those zones are
  6883. signed periodically, and every new signature is an update to the zone, there are
  6884. many revisions of zones. This results in a problem with bigger zones as there
  6885. are lots of records that have been signed again but no major changes. Also
  6886. trying to add records that are unknown that require a different format take time
  6887. as they cause a CLI call of the namestore. Furthermore certain record types
  6888. need transformation into a GNS compatible format which, depending on the record
  6889. type, takes more time.
  6890. Further a blacklist was added to drop for instance DNSSEC related records. Also
  6891. if a record type is neither in the white list nor the blacklist it is considered
  6892. as a loss of data and a message is shown to the user. This helps with
  6893. transparency and also with contributing, as the not supported record types can
  6894. then be added accordingly.
  6895. @node DNS Zone Size
  6896. @subsubsection DNS Zone Size
  6897. Another very big problem exists with very large zones. When migrating a small
  6898. zone the delay between adding of records and their expiry is negligible. However
  6899. when working with big zones that easily have more than a few million records
  6900. this delay becomes a problem.
  6901. Records will start to expire well before the zone has finished migrating. This
  6902. is usually not a problem but can cause a high CPU load when a peer is restarted
  6903. and the records have expired.
  6904. A good solution has not been found yet. One of the idea that floated around was
  6905. that the records should be added with the s (shadow) flag to keep the records
  6906. resolvable even if they expired. However this would introduce the problem of how
  6907. to detect if a record has been removed from the zone and would require deletion
  6908. of said record(s).
  6909. Another problem that still persists is how to refresh records. Expired records
  6910. are still displayed when calling gnunet-namestore but do not resolve with
  6911. gnunet-gns. Zonemaster will sign the expired records again and make sure that
  6912. the records are still valid. With a recent change this was fixed as gnunet-gns
  6913. to improve the suffix lookup which allows for a fast lookup even with thousands
  6914. of local egos.
  6915. Currently the pace of adding records in general is around 10 records per second.
  6916. Crypto is the upper limit for adding of records. The performance of your machine
  6917. can be tested with the perf_crypto_* tools. There is still a big discrepancy
  6918. between the pace of Ascension and the theoretical limit.
  6919. A performance metric for measuring improvements has not yet been implemented in
  6920. Ascension.
  6921. @node Performance
  6922. @subsubsection Performance
  6923. The performance when migrating a zone using the Ascension tool is limited by a
  6924. handful of factors. First of all ascension is written in Python3 and calls the
  6925. CLI tools of GNUnet. This is comparable to a fork and exec call which costs a
  6926. few CPU cycles. Furthermore all the records that are added to the same
  6927. label are signed using the zones private key. This signing operation is very
  6928. resource heavy and was optimized during development by adding the '-R'
  6929. (Recordline) option to gnunet-namestore which allows to specify multiple records
  6930. using the CLI tool. Assuming that in a TLD zone every domain has at least two
  6931. name servers this halves the amount of signatures needed.
  6932. Another improvement that could be made is with the addition of multiple threads
  6933. or using asynchronous subprocesses when opening the GNUnet CLI tools. This could
  6934. be implemented by simply creating more workers in the program but performance
  6935. improvements were not tested.
  6936. Ascension was tested using different hardware and database backends. Performance
  6937. differences between SQLite and postgresql are marginal and almost non existent.
  6938. What did make a huge impact on record adding performance was the storage medium.
  6939. On a traditional mechanical hard drive adding of records were slow compared to a
  6940. solid state disk.
  6941. In conclusion there are many bottlenecks still around in the program, namely the
  6942. single threaded implementation and inefficient, sequential calls of
  6943. gnunet-namestore. In the future a solution that uses the C API would be cleaner
  6944. and better.
  6945. @cindex GNS Namecache
  6946. @node GNS Namecache
  6947. @section GNS Namecache
  6948. The NAMECACHE subsystem is responsible for caching (encrypted) resolution
  6949. results of the GNU Name System (GNS). GNS makes zone information available
  6950. to other users via the DHT. However, as accessing the DHT for every
  6951. lookup is expensive (and as the DHT's local cache is lost whenever the
  6952. peer is restarted), GNS uses the NAMECACHE as a more persistent cache for
  6953. DHT lookups.
  6954. Thus, instead of always looking up every name in the DHT, GNS first
  6955. checks if the result is already available locally in the NAMECACHE.
  6956. Only if there is no result in the NAMECACHE, GNS queries the DHT.
  6957. The NAMECACHE stores data in the same (encrypted) format as the DHT.
  6958. It thus makes no sense to iterate over all items in the
  6959. NAMECACHE --- the NAMECACHE does not have a way to provide the keys
  6960. required to decrypt the entries.
  6961. Blocks in the NAMECACHE share the same expiration mechanism as blocks in
  6962. the DHT --- the block expires wheneever any of the records in
  6963. the (encrypted) block expires.
  6964. The expiration time of the block is the only information stored in
  6965. plaintext. The NAMECACHE service internally performs all of the required
  6966. work to expire blocks, clients do not have to worry about this.
  6967. Also, given that NAMECACHE stores only GNS blocks that local users
  6968. requested, there is no configuration option to limit the size of the
  6969. NAMECACHE. It is assumed to be always small enough (a few MB) to fit on
  6970. the drive.
  6971. The NAMECACHE supports the use of different database backends via a
  6972. plugin API.
  6973. @menu
  6974. * libgnunetnamecache::
  6975. * The NAMECACHE Client-Service Protocol::
  6976. * The NAMECACHE Plugin API::
  6977. @end menu
  6978. @node libgnunetnamecache
  6979. @subsection libgnunetnamecache
  6980. The NAMECACHE API consists of five simple functions. First, there is
  6981. @code{GNUNET_NAMECACHE_connect} to connect to the NAMECACHE service.
  6982. This returns the handle required for all other operations on the
  6983. NAMECACHE. Using @code{GNUNET_NAMECACHE_block_cache} clients can insert a
  6984. block into the cache.
  6985. @code{GNUNET_NAMECACHE_lookup_block} can be used to lookup blocks that
  6986. were stored in the NAMECACHE. Both operations can be canceled using
  6987. @code{GNUNET_NAMECACHE_cancel}. Note that canceling a
  6988. @code{GNUNET_NAMECACHE_block_cache} operation can result in the block
  6989. being stored in the NAMECACHE --- or not. Cancellation primarily ensures
  6990. that the continuation function with the result of the operation will no
  6991. longer be invoked.
  6992. Finally, @code{GNUNET_NAMECACHE_disconnect} closes the connection to the
  6993. NAMECACHE.
  6994. The maximum size of a block that can be stored in the NAMECACHE is
  6995. @code{GNUNET_NAMECACHE_MAX_VALUE_SIZE}, which is defined to be 63 kB.
  6996. @node The NAMECACHE Client-Service Protocol
  6997. @subsection The NAMECACHE Client-Service Protocol
  6998. All messages in the NAMECACHE IPC protocol start with the
  6999. @code{struct GNUNET_NAMECACHE_Header} which adds a request
  7000. ID (32-bit integer) to the standard message header.
  7001. The request ID is used to match requests with the
  7002. respective responses from the NAMECACHE, as they are allowed to happen
  7003. out-of-order.
  7004. @menu
  7005. * Lookup::
  7006. * Store::
  7007. @end menu
  7008. @node Lookup
  7009. @subsubsection Lookup
  7010. The @code{struct LookupBlockMessage} is used to lookup a block stored in
  7011. the cache.
  7012. It contains the query hash. The NAMECACHE always responds with a
  7013. @code{struct LookupBlockResponseMessage}. If the NAMECACHE has no
  7014. response, it sets the expiration time in the response to zero.
  7015. Otherwise, the response is expected to contain the expiration time, the
  7016. ECDSA signature, the derived key and the (variable-size) encrypted data
  7017. of the block.
  7018. @node Store
  7019. @subsubsection Store
  7020. The @code{struct BlockCacheMessage} is used to cache a block in the
  7021. NAMECACHE.
  7022. It has the same structure as the @code{struct LookupBlockResponseMessage}.
  7023. The service responds with a @code{struct BlockCacheResponseMessage} which
  7024. contains the result of the operation (success or failure).
  7025. In the future, we might want to make it possible to provide an error
  7026. message as well.
  7027. @node The NAMECACHE Plugin API
  7028. @subsection The NAMECACHE Plugin API
  7029. The NAMECACHE plugin API consists of two functions, @code{cache_block} to
  7030. store a block in the database, and @code{lookup_block} to lookup a block
  7031. in the database.
  7032. @menu
  7033. * Lookup2::
  7034. * Store2::
  7035. @end menu
  7036. @node Lookup2
  7037. @subsubsection Lookup2
  7038. The @code{lookup_block} function is expected to return at most one block
  7039. to the iterator, and return @code{GNUNET_NO} if there were no non-expired
  7040. results.
  7041. If there are multiple non-expired results in the cache, the lookup is
  7042. supposed to return the result with the largest expiration time.
  7043. @node Store2
  7044. @subsubsection Store2
  7045. The @code{cache_block} function is expected to try to store the block in
  7046. the database, and return @code{GNUNET_SYSERR} if this was not possible
  7047. for any reason.
  7048. Furthermore, @code{cache_block} is expected to implicitly perform cache
  7049. maintenance and purge blocks from the cache that have expired. Note that
  7050. @code{cache_block} might encounter the case where the database already has
  7051. another block stored under the same key. In this case, the plugin must
  7052. ensure that the block with the larger expiration time is preserved.
  7053. Obviously, this can done either by simply adding new blocks and selecting
  7054. for the most recent expiration time during lookup, or by checking which
  7055. block is more recent during the store operation.
  7056. @cindex REVOCATION Subsystem
  7057. @node REVOCATION Subsystem
  7058. @section REVOCATION Subsystem
  7059. The REVOCATION subsystem is responsible for key revocation of Egos.
  7060. If a user learns that theis private key has been compromised or has lost
  7061. it, they can use the REVOCATION system to inform all of the other users
  7062. that their private key is no longer valid.
  7063. The subsystem thus includes ways to query for the validity of keys and to
  7064. propagate revocation messages.
  7065. @menu
  7066. * Dissemination::
  7067. * Revocation Message Design Requirements::
  7068. * libgnunetrevocation::
  7069. * The REVOCATION Client-Service Protocol::
  7070. * The REVOCATION Peer-to-Peer Protocol::
  7071. @end menu
  7072. @node Dissemination
  7073. @subsection Dissemination
  7074. When a revocation is performed, the revocation is first of all
  7075. disseminated by flooding the overlay network.
  7076. The goal is to reach every peer, so that when a peer needs to check if a
  7077. key has been revoked, this will be purely a local operation where the
  7078. peer looks at its local revocation list. Flooding the network is also the
  7079. most robust form of key revocation --- an adversary would have to control
  7080. a separator of the overlay graph to restrict the propagation of the
  7081. revocation message. Flooding is also very easy to implement --- peers that
  7082. receive a revocation message for a key that they have never seen before
  7083. simply pass the message to all of their neighbours.
  7084. Flooding can only distribute the revocation message to peers that are
  7085. online.
  7086. In order to notify peers that join the network later, the revocation
  7087. service performs efficient set reconciliation over the sets of known
  7088. revocation messages whenever two peers (that both support REVOCATION
  7089. dissemination) connect.
  7090. The SET service is used to perform this operation efficiently.
  7091. @node Revocation Message Design Requirements
  7092. @subsection Revocation Message Design Requirements
  7093. However, flooding is also quite costly, creating O(|E|) messages on a
  7094. network with |E| edges.
  7095. Thus, revocation messages are required to contain a proof-of-work, the
  7096. result of an expensive computation (which, however, is cheap to verify).
  7097. Only peers that have expended the CPU time necessary to provide
  7098. this proof will be able to flood the network with the revocation message.
  7099. This ensures that an attacker cannot simply flood the network with
  7100. millions of revocation messages. The proof-of-work required by GNUnet is
  7101. set to take days on a typical PC to compute; if the ability to quickly
  7102. revoke a key is needed, users have the option to pre-compute revocation
  7103. messages to store off-line and use instantly after their key has expired.
  7104. Revocation messages must also be signed by the private key that is being
  7105. revoked. Thus, they can only be created while the private key is in the
  7106. possession of the respective user. This is another reason to create a
  7107. revocation message ahead of time and store it in a secure location.
  7108. @node libgnunetrevocation
  7109. @subsection libgnunetrevocation
  7110. The REVOCATION API consists of two parts, to query and to issue
  7111. revocations.
  7112. @menu
  7113. * Querying for revoked keys::
  7114. * Preparing revocations::
  7115. * Issuing revocations::
  7116. @end menu
  7117. @node Querying for revoked keys
  7118. @subsubsection Querying for revoked keys
  7119. @code{GNUNET_REVOCATION_query} is used to check if a given ECDSA public
  7120. key has been revoked.
  7121. The given callback will be invoked with the result of the check.
  7122. The query can be canceled using @code{GNUNET_REVOCATION_query_cancel} on
  7123. the return value.
  7124. @node Preparing revocations
  7125. @subsubsection Preparing revocations
  7126. It is often desirable to create a revocation record ahead-of-time and
  7127. store it in an off-line location to be used later in an emergency.
  7128. This is particularly true for GNUnet revocations, where performing the
  7129. revocation operation itself is computationally expensive and thus is
  7130. likely to take some time.
  7131. Thus, if users want the ability to perform revocations quickly in an
  7132. emergency, they must pre-compute the revocation message.
  7133. The revocation API enables this with two functions that are used to
  7134. compute the revocation message, but not trigger the actual revocation
  7135. operation.
  7136. @code{GNUNET_REVOCATION_check_pow} should be used to calculate the
  7137. proof-of-work required in the revocation message. This function takes the
  7138. public key, the required number of bits for the proof of work (which in
  7139. GNUnet is a network-wide constant) and finally a proof-of-work number as
  7140. arguments.
  7141. The function then checks if the given proof-of-work number is a valid
  7142. proof of work for the given public key. Clients preparing a revocation
  7143. are expected to call this function repeatedly (typically with a
  7144. monotonically increasing sequence of numbers of the proof-of-work number)
  7145. until a given number satisfies the check.
  7146. That number should then be saved for later use in the revocation
  7147. operation.
  7148. @code{GNUNET_REVOCATION_sign_revocation} is used to generate the
  7149. signature that is required in a revocation message.
  7150. It takes the private key that (possibly in the future) is to be revoked
  7151. and returns the signature.
  7152. The signature can again be saved to disk for later use, which will then
  7153. allow performing a revocation even without access to the private key.
  7154. @node Issuing revocations
  7155. @subsubsection Issuing revocations
  7156. Given a ECDSA public key, the signature from @code{GNUNET_REVOCATION_sign}
  7157. and the proof-of-work,
  7158. @code{GNUNET_REVOCATION_revoke} can be used to perform the
  7159. actual revocation. The given callback is called upon completion of the
  7160. operation. @code{GNUNET_REVOCATION_revoke_cancel} can be used to stop the
  7161. library from calling the continuation; however, in that case it is
  7162. undefined whether or not the revocation operation will be executed.
  7163. @node The REVOCATION Client-Service Protocol
  7164. @subsection The REVOCATION Client-Service Protocol
  7165. The REVOCATION protocol consists of four simple messages.
  7166. A @code{QueryMessage} containing a public ECDSA key is used to check if a
  7167. particular key has been revoked. The service responds with a
  7168. @code{QueryResponseMessage} which simply contains a bit that says if the
  7169. given public key is still valid, or if it has been revoked.
  7170. The second possible interaction is for a client to revoke a key by
  7171. passing a @code{RevokeMessage} to the service. The @code{RevokeMessage}
  7172. contains the ECDSA public key to be revoked, a signature by the
  7173. corresponding private key and the proof-of-work, The service responds
  7174. with a @code{RevocationResponseMessage} which can be used to indicate
  7175. that the @code{RevokeMessage} was invalid (i.e. proof of work incorrect),
  7176. or otherwise indicates that the revocation has been processed
  7177. successfully.
  7178. @node The REVOCATION Peer-to-Peer Protocol
  7179. @subsection The REVOCATION Peer-to-Peer Protocol
  7180. Revocation uses two disjoint ways to spread revocation information among
  7181. peers.
  7182. First of all, P2P gossip exchanged via CORE-level neighbours is used to
  7183. quickly spread revocations to all connected peers.
  7184. Second, whenever two peers (that both support revocations) connect,
  7185. the SET service is used to compute the union of the respective revocation
  7186. sets.
  7187. In both cases, the exchanged messages are @code{RevokeMessage}s which
  7188. contain the public key that is being revoked, a matching ECDSA signature,
  7189. and a proof-of-work.
  7190. Whenever a peer learns about a new revocation this way, it first
  7191. validates the signature and the proof-of-work, then stores it to disk
  7192. (typically to a file $GNUNET_DATA_HOME/revocation.dat) and finally
  7193. spreads the information to all directly connected neighbours.
  7194. For computing the union using the SET service, the peer with the smaller
  7195. hashed peer identity will connect (as a "client" in the two-party set
  7196. protocol) to the other peer after one second (to reduce traffic spikes
  7197. on connect) and initiate the computation of the set union.
  7198. All revocation services use a common hash to identify the SET operation
  7199. over revocation sets.
  7200. The current implementation accepts revocation set union operations from
  7201. all peers at any time; however, well-behaved peers should only initiate
  7202. this operation once after establishing a connection to a peer with a
  7203. larger hashed peer identity.
  7204. @cindex FS
  7205. @cindex FS Subsystem
  7206. @node File-sharing (FS) Subsystem
  7207. @section File-sharing (FS) Subsystem
  7208. This chapter describes the details of how the file-sharing service works.
  7209. As with all services, it is split into an API (libgnunetfs), the service
  7210. process (gnunet-service-fs) and user interface(s).
  7211. The file-sharing service uses the datastore service to store blocks and
  7212. the DHT (and indirectly datacache) for lookups for non-anonymous
  7213. file-sharing.
  7214. Furthermore, the file-sharing service uses the block library (and the
  7215. block fs plugin) for validation of DHT operations.
  7216. In contrast to many other services, libgnunetfs is rather complex since
  7217. the client library includes a large number of high-level abstractions;
  7218. this is necessary since the Fs service itself largely only operates on
  7219. the block level.
  7220. The FS library is responsible for providing a file-based abstraction to
  7221. applications, including directories, meta data, keyword search,
  7222. verification, and so on.
  7223. The method used by GNUnet to break large files into blocks and to use
  7224. keyword search is called the
  7225. "Encoding for Censorship Resistant Sharing" (ECRS).
  7226. ECRS is largely implemented in the fs library; block validation is also
  7227. reflected in the block FS plugin and the FS service.
  7228. ECRS on-demand encoding is implemented in the FS service.
  7229. NOTE: The documentation in this chapter is quite incomplete.
  7230. @menu
  7231. * Encoding for Censorship-Resistant Sharing (ECRS)::
  7232. * File-sharing persistence directory structure::
  7233. @end menu
  7234. @cindex ECRS
  7235. @cindex Encoding for Censorship-Resistant Sharing
  7236. @node Encoding for Censorship-Resistant Sharing (ECRS)
  7237. @subsection Encoding for Censorship-Resistant Sharing (ECRS)
  7238. When GNUnet shares files, it uses a content encoding that is called ECRS,
  7239. the Encoding for Censorship-Resistant Sharing.
  7240. Most of ECRS is described in the (so far unpublished) research paper
  7241. attached to this page. ECRS obsoletes the previous ESED and ESED II
  7242. encodings which were used in GNUnet before version 0.7.0.
  7243. The rest of this page assumes that the reader is familiar with the
  7244. attached paper. What follows is a description of some minor extensions
  7245. that GNUnet makes over what is described in the paper.
  7246. The reason why these extensions are not in the paper is that we felt
  7247. that they were obvious or trivial extensions to the original scheme and
  7248. thus did not warrant space in the research report.
  7249. @menu
  7250. * Namespace Advertisements::
  7251. * KSBlocks::
  7252. @end menu
  7253. @node Namespace Advertisements
  7254. @subsubsection Namespace Advertisements
  7255. @c %**FIXME: all zeroses -> ?
  7256. An @code{SBlock} with identifier all zeros is a signed
  7257. advertisement for a namespace. This special @code{SBlock} contains
  7258. metadata describing the content of the namespace.
  7259. Instead of the name of the identifier for a potential update, it contains
  7260. the identifier for the root of the namespace.
  7261. The URI should always be empty. The @code{SBlock} is signed with the
  7262. content provider's RSA private key (just like any other SBlock). Peers
  7263. can search for @code{SBlock}s in order to find out more about a namespace.
  7264. @node KSBlocks
  7265. @subsubsection KSBlocks
  7266. GNUnet implements @code{KSBlocks} which are @code{KBlocks} that, instead
  7267. of encrypting a CHK and metadata, encrypt an @code{SBlock} instead.
  7268. In other words, @code{KSBlocks} enable GNUnet to find @code{SBlocks}
  7269. using the global keyword search.
  7270. Usually the encrypted @code{SBlock} is a namespace advertisement.
  7271. The rationale behind @code{KSBlock}s and @code{SBlock}s is to enable
  7272. peers to discover namespaces via keyword searches, and, to associate
  7273. useful information with namespaces. When GNUnet finds @code{KSBlocks}
  7274. during a normal keyword search, it adds the information to an internal
  7275. list of discovered namespaces. Users looking for interesting namespaces
  7276. can then inspect this list, reducing the need for out-of-band discovery
  7277. of namespaces.
  7278. Naturally, namespaces (or more specifically, namespace advertisements) can
  7279. also be referenced from directories, but @code{KSBlock}s should make it
  7280. easier to advertise namespaces for the owner of the pseudonym since they
  7281. eliminate the need to first create a directory.
  7282. Collections are also advertised using @code{KSBlock}s.
  7283. @c https://old.gnunet.org/sites/default/files/ecrs.pdf
  7284. @node File-sharing persistence directory structure
  7285. @subsection File-sharing persistence directory structure
  7286. This section documents how the file-sharing library implements
  7287. persistence of file-sharing operations and specifically the resulting
  7288. directory structure.
  7289. This code is only active if the @code{GNUNET_FS_FLAGS_PERSISTENCE} flag
  7290. was set when calling @code{GNUNET_FS_start}.
  7291. In this case, the file-sharing library will try hard to ensure that all
  7292. major operations (searching, downloading, publishing, unindexing) are
  7293. persistent, that is, can live longer than the process itself.
  7294. More specifically, an operation is supposed to live until it is
  7295. explicitly stopped.
  7296. If @code{GNUNET_FS_stop} is called before an operation has been stopped, a
  7297. @code{SUSPEND} event is generated and then when the process calls
  7298. @code{GNUNET_FS_start} next time, a @code{RESUME} event is generated.
  7299. Additionally, even if an application crashes (segfault, SIGKILL, system
  7300. crash) and hence @code{GNUNET_FS_stop} is never called and no
  7301. @code{SUSPEND} events are generated, operations are still resumed (with
  7302. @code{RESUME} events).
  7303. This is implemented by constantly writing the current state of the
  7304. file-sharing operations to disk.
  7305. Specifically, the current state is always written to disk whenever
  7306. anything significant changes (the exception are block-wise progress in
  7307. publishing and unindexing, since those operations would be slowed down
  7308. significantly and can be resumed cheaply even without detailed
  7309. accounting).
  7310. Note that if the process crashes (or is killed) during a serialization
  7311. operation, FS does not guarantee that this specific operation is
  7312. recoverable (no strict transactional semantics, again for performance
  7313. reasons). However, all other unrelated operations should resume nicely.
  7314. Since we need to serialize the state continuously and want to recover as
  7315. much as possible even after crashing during a serialization operation,
  7316. we do not use one large file for serialization.
  7317. Instead, several directories are used for the various operations.
  7318. When @code{GNUNET_FS_start} executes, the master directories are scanned
  7319. for files describing operations to resume.
  7320. Sometimes, these operations can refer to related operations in child
  7321. directories which may also be resumed at this point.
  7322. Note that corrupted files are cleaned up automatically.
  7323. However, dangling files in child directories (those that are not
  7324. referenced by files from the master directories) are not automatically
  7325. removed.
  7326. Persistence data is kept in a directory that begins with the "STATE_DIR"
  7327. prefix from the configuration file
  7328. (by default, "$SERVICEHOME/persistence/") followed by the name of the
  7329. client as given to @code{GNUNET_FS_start} (for example, "gnunet-gtk")
  7330. followed by the actual name of the master or child directory.
  7331. The names for the master directories follow the names of the operations:
  7332. @itemize @bullet
  7333. @item "search"
  7334. @item "download"
  7335. @item "publish"
  7336. @item "unindex"
  7337. @end itemize
  7338. Each of the master directories contains names (chosen at random) for each
  7339. active top-level (master) operation.
  7340. Note that a download that is associated with a search result is not a
  7341. top-level operation.
  7342. In contrast to the master directories, the child directories are only
  7343. consulted when another operation refers to them.
  7344. For each search, a subdirectory (named after the master search
  7345. synchronization file) contains the search results.
  7346. Search results can have an associated download, which is then stored in
  7347. the general "download-child" directory.
  7348. Downloads can be recursive, in which case children are stored in
  7349. subdirectories mirroring the structure of the recursive download
  7350. (either starting in the master "download" directory or in the
  7351. "download-child" directory depending on how the download was initiated).
  7352. For publishing operations, the "publish-file" directory contains
  7353. information about the individual files and directories that are part of
  7354. the publication.
  7355. However, this directory structure is flat and does not mirror the
  7356. structure of the publishing operation.
  7357. Note that unindex operations cannot have associated child operations.
  7358. @cindex REGEX subsystem
  7359. @node REGEX Subsystem
  7360. @section REGEX Subsystem
  7361. Using the REGEX subsystem, you can discover peers that offer a particular
  7362. service using regular expressions.
  7363. The peers that offer a service specify it using a regular expressions.
  7364. Peers that want to patronize a service search using a string.
  7365. The REGEX subsystem will then use the DHT to return a set of matching
  7366. offerers to the patrons.
  7367. For the technical details, we have Max's defense talk and Max's Master's
  7368. thesis.
  7369. @c An additional publication is under preparation and available to
  7370. @c team members (in Git).
  7371. @c FIXME: Where is the file? Point to it. Assuming that it's szengel2012ms
  7372. @menu
  7373. * How to run the regex profiler::
  7374. @end menu
  7375. @node How to run the regex profiler
  7376. @subsection How to run the regex profiler
  7377. The gnunet-regex-profiler can be used to profile the usage of mesh/regex
  7378. for a given set of regular expressions and strings.
  7379. Mesh/regex allows you to announce your peer ID under a certain regex and
  7380. search for peers matching a particular regex using a string.
  7381. See @uref{https://bib.gnunet.org/full/date.html#2012_5f2, szengel2012ms} for a full
  7382. introduction.
  7383. First of all, the regex profiler uses GNUnet testbed, thus all the
  7384. implications for testbed also apply to the regex profiler
  7385. (for example you need password-less ssh login to the machines listed in
  7386. your hosts file).
  7387. @strong{Configuration}
  7388. Moreover, an appropriate configuration file is needed.
  7389. Generally you can refer to the
  7390. @file{contrib/regex_profiler_infiniband.conf} file in the sourcecode
  7391. of GNUnet for an example configuration.
  7392. In the following paragraph the important details are highlighted.
  7393. Announcing of the regular expressions is done by the
  7394. gnunet-daemon-regexprofiler, therefore you have to make sure it is
  7395. started, by adding it to the START_ON_DEMAND set of ARM:
  7396. @example
  7397. [regexprofiler]
  7398. START_ON_DEMAND = YES
  7399. @end example
  7400. @noindent
  7401. Furthermore you have to specify the location of the binary:
  7402. @example
  7403. [regexprofiler]
  7404. # Location of the gnunet-daemon-regexprofiler binary.
  7405. BINARY = /home/szengel/gnunet/src/mesh/.libs/gnunet-daemon-regexprofiler
  7406. # Regex prefix that will be applied to all regular expressions and
  7407. # search string.
  7408. REGEX_PREFIX = "GNVPN-0001-PAD"
  7409. @end example
  7410. @noindent
  7411. When running the profiler with a large scale deployment, you probably
  7412. want to reduce the workload of each peer.
  7413. Use the following options to do this.
  7414. @example
  7415. [dht]
  7416. # Force network size estimation
  7417. FORCE_NSE = 1
  7418. [dhtcache]
  7419. DATABASE = heap
  7420. # Disable RC-file for Bloom filter? (for benchmarking with limited IO
  7421. # availability)
  7422. DISABLE_BF_RC = YES
  7423. # Disable Bloom filter entirely
  7424. DISABLE_BF = YES
  7425. [nse]
  7426. # Minimize proof-of-work CPU consumption by NSE
  7427. WORKBITS = 1
  7428. @end example
  7429. @noindent
  7430. @strong{Options}
  7431. To finally run the profiler some options and the input data need to be
  7432. specified on the command line.
  7433. @example
  7434. gnunet-regex-profiler -c config-file -d log-file -n num-links \
  7435. -p path-compression-length -s search-delay -t matching-timeout \
  7436. -a num-search-strings hosts-file policy-dir search-strings-file
  7437. @end example
  7438. @noindent
  7439. Where...
  7440. @itemize @bullet
  7441. @item ... @code{config-file} means the configuration file created earlier.
  7442. @item ... @code{log-file} is the file where to write statistics output.
  7443. @item ... @code{num-links} indicates the number of random links between
  7444. started peers.
  7445. @item ... @code{path-compression-length} is the maximum path compression
  7446. length in the DFA.
  7447. @item ... @code{search-delay} time to wait between peers finished linking
  7448. and starting to match strings.
  7449. @item ... @code{matching-timeout} timeout after which to cancel the
  7450. searching.
  7451. @item ... @code{num-search-strings} number of strings in the
  7452. search-strings-file.
  7453. @item ... the @code{hosts-file} should contain a list of hosts for the
  7454. testbed, one per line in the following format:
  7455. @itemize @bullet
  7456. @item @code{user@@host_ip:port}
  7457. @end itemize
  7458. @item ... the @code{policy-dir} is a folder containing text files
  7459. containing one or more regular expressions. A peer is started for each
  7460. file in that folder and the regular expressions in the corresponding file
  7461. are announced by this peer.
  7462. @item ... the @code{search-strings-file} is a text file containing search
  7463. strings, one in each line.
  7464. @end itemize
  7465. @noindent
  7466. You can create regular expressions and search strings for every AS in the
  7467. Internet using the attached scripts. You need one of the
  7468. @uref{http://data.caida.org/datasets/routing/routeviews-prefix2as/, CAIDA routeviews prefix2as}
  7469. data files for this. Run
  7470. @example
  7471. create_regex.py <filename> <output path>
  7472. @end example
  7473. @noindent
  7474. to create the regular expressions and
  7475. @example
  7476. create_strings.py <input path> <outfile>
  7477. @end example
  7478. @noindent
  7479. to create a search strings file from the previously created
  7480. regular expressions.
  7481. @cindex REST subsystem
  7482. @node REST Subsystem
  7483. @section REST Subsystem
  7484. Using the REST subsystem, you can expose REST-based APIs or services.
  7485. The REST service is designed as a pluggable architecture.
  7486. To create a new REST endpoint, simply add a library in the form
  7487. ``plugin_rest_*''.
  7488. The REST service will automatically load all REST plugins on startup.
  7489. @strong{Configuration}
  7490. The REST service can be configured in various ways.
  7491. The reference config file can be found in
  7492. @file{src/rest/rest.conf}:
  7493. @example
  7494. [rest]
  7495. REST_PORT=7776
  7496. REST_ALLOW_HEADERS=Authorization,Accept,Content-Type
  7497. REST_ALLOW_ORIGIN=*
  7498. REST_ALLOW_CREDENTIALS=true
  7499. @end example
  7500. The port as well as
  7501. @deffn{cross-origin resource sharing} (CORS)
  7502. @end deffn
  7503. headers that are supposed to be advertised by the rest service are
  7504. configurable.
  7505. @menu
  7506. * Namespace considerations::
  7507. * Endpoint documentation::
  7508. @end menu
  7509. @node Namespace considerations
  7510. @subsection Namespace considerations
  7511. The @command{gnunet-rest-service} will load all plugins that are installed.
  7512. As such it is important that the endpoint namespaces do not clash.
  7513. For example, plugin X might expose the endpoint ``/xxx'' while plugin Y
  7514. exposes endpoint ``/xxx/yyy''.
  7515. This is a problem if plugin X is also supposed to handle a call
  7516. to ``/xxx/yyy''.
  7517. Currently the REST service will not complain or warn about such clashes,
  7518. so please make sure that endpoints are unambiguous.
  7519. @node Endpoint documentation
  7520. @subsection Endpoint documentation
  7521. This is WIP. Endpoints should be documented appropriately.
  7522. Preferably using annotations.
  7523. @cindex RPS Subsystem
  7524. @node RPS Subsystem
  7525. @section RPS Subsystem
  7526. In literature, Random Peer Sampling (RPS) refers to the problem of
  7527. reliably@footnote{"Reliable" in this context means having no bias,
  7528. neither spatial, nor temporal, nor through malicious activity.} drawing
  7529. random samples from an unstructured p2p network.
  7530. Doing so in a reliable manner is not only hard because of inherent
  7531. problems but also because of possible malicious peers that could try to
  7532. bias the selection.
  7533. It is useful for all kind of gossip protocols that require the selection
  7534. of random peers in the whole network like gathering statistics,
  7535. spreading and aggregating information in the network, load balancing and
  7536. overlay topology management.
  7537. The approach chosen in the RPS service implementation in GNUnet follows
  7538. the @uref{https://bib.gnunet.org/full/date.html\#2009_5f0, Brahms}
  7539. design.
  7540. The current state is "work in progress". There are a lot of things that
  7541. need to be done, primarily finishing the experimental evaluation and a
  7542. re-design of the API.
  7543. The abstract idea is to subscribe to connect to/start the RPS service
  7544. and request random peers that will be returned when they represent a
  7545. random selection from the whole network with high probability.
  7546. An additional feature to the original Brahms-design is the selection of
  7547. sub-groups: The GNUnet implementation of RPS enables clients to ask for
  7548. random peers from a group that is defined by a common shared secret.
  7549. (The secret could of course also be public, depending on the use-case.)
  7550. Another addition to the original protocol was made: The sampler
  7551. mechanism that was introduced in Brahms was slightly adapted and used to
  7552. actually sample the peers and returned to the client.
  7553. This is necessary as the original design only keeps peers connected to
  7554. random other peers in the network. In order to return random peers to
  7555. client requests independently random, they cannot be drawn from the
  7556. connected peers.
  7557. The adapted sampler makes sure that each request for random peers is
  7558. independent from the others.
  7559. @menu
  7560. * Brahms::
  7561. @end menu
  7562. @node Brahms
  7563. @subsection Brahms
  7564. The high-level concept of Brahms is two-fold: Combining push-pull gossip
  7565. with locally fixing a assumed bias using cryptographic min-wise
  7566. permutations.
  7567. The central data structure is the view - a peer's current local sample.
  7568. This view is used to select peers to push to and pull from.
  7569. This simple mechanism can be biased easily. For this reason Brahms
  7570. 'fixes' the bias by using the so-called sampler. A data structure that
  7571. takes a list of elements as input and outputs a random one of them
  7572. independently of the frequency in the input set. Both an element that
  7573. was put into the sampler a single time and an element that was put into
  7574. it a million times have the same probability of being the output.
  7575. This is achieved with exploiting min-wise independent
  7576. permutations.
  7577. In the RPS service we use HMACs: On the initialisation of a sampler
  7578. element, a key is chosen at random. On each input the HMAC with the
  7579. random key is computed. The sampler element keeps the element with the
  7580. minimal HMAC.
  7581. In order to fix the bias in the view, a fraction of the elements in the
  7582. view are sampled through the sampler from the random stream of peer IDs.
  7583. According to the theoretical analysis of Bortnikov et al. this suffices
  7584. to keep the network connected and having random peers in the view.