Network(Programming(Beyond( Sockets(

Transcription

nichev

Overview Low- sgrowinginpopularitySomecoolacademicwork

Low- ‐LevelSockets AddressFamily AF PACKET:– Sockettype SOCK RAW: SeeLink- angetnon- ‐IPpackets.– Sockettype SOCK DGRAM: SCTP,DCCP,etc. igher- ‐levelprotocol,incominginterface,etc.

Overview Low- ‐levelsocketsMature/Tradi academicwork

Event- ‐DrivenvsThreadbasedEvent- ‐DrivenThread- ,locksNothread- read–EasilyuFlizemulF- ‐can’teasilyuFlizecores.mulF- ‐coresStackRippingNostackripping.

StackRippingon ntfs get file(char *file name, client *c) {.// Need to get the i-node from remote serversend(remote, i node req msg);inode recv();for (i 0; i num blocks; i ) {// Request block i from remote server i.send(remote i, block req msg);}for (i 0; i num blocks; i ) {block i recv();}send(c, all blocks);}

StackRippingon ntfs get file(char *file name, client *c) {fdcb(remote, selwrite, wrap(get inode, remote, i node req, file name);}get inode(int remote, char *i node req, char *i node req ) {send(remote, i node req);. . .fdcb(remote, selread, wrap(got inode, remote, i node req,file name));}got inode(int remote, char *i node req, char *file name, char *inode){for (i 0; i num blocks; i ) {fdcb(remote i, selwrite, wrap(get block, remote i));}}get block() {}got block() {}send response() {}

ecallsMoreappropriateinsome- �c(MPI)applicaFons.Morefreedom:- ‐BatchMessages- ‐Preprocess- ‐CustomreacFontomal- ‐formedmessages.Easiertouse:- ‐Nomessageassembly- ‐Nomal- ‐formedchecking- ‐YourfuncFonjustgetscalledandresultsentback- ‐ExactsemanFcsaretricky.- ‐UsuallynotopFmizedforlargedatatransfers.

LanguageSpecificLibraries PythonJavaCC

AvailableLibraries:Python t- . Twisted:– Probablythemostpopularlibrary– Hasalotofstuff,butquitemodular– Event- e,but(hopefully)cleanercode.– Well- ‐maintainedanddocumented

AvailableLibraries:Java Java.NIO:– ReplacementofJava.IO.– Aratherhigh- ‐levelwrappingofOSprimiFves.Select- ‐ Selector.Socket- ‐ Channel.– GoodbufferabstracFon.

AvailableLibraries:Java:Negy ExtensibleEvent- ‐DrivenFramework– Separatesdatahandlingintoseverallayers Goodsupportforthreadmanagement Manyprotocollibrariesbutquitemodular Seemstobehigh- ‐performance(avoidsunnecessarycoping) Theothersidedoesnothavetobeinjava

AvailableLibraries:Java:JavaRMI AnObject- ‐OrientedRPCsystem. ConsandProsofRPCsystems WithdefaultimplementaFon,bothsideshavetobeJava aboutCORBAlater)

AvailableLibraries:Java:Jini(River) gservices.– SupportforservicedefiniFon(naming,federaFons)– – SupportforMobileCode.Uhh. Usefulifyouarebuildinga( rary.

AvailableLibraries:C LongLiveSockets! Libevent:– habitmorefuncFonalitylikeFmers.– WellmaintainedandacFvelydeveloped.

AvailableLibraries:C BOOST.ASIO– ketsandprovidesotherusefulfeatures.– Thisisgreatifyouwanttowriteaportablehigh- pport(exceptforIP/TCP/UDP/SSL).– ofboost)

AvailableLibraries:C ACE– Averyheavylibrarywith20 designpagerns.– � IPC.– WasusedinSatellites

LanguageIndependentMiddleware rs:ApacheAvro,languagespecificserializaFon,etc.

ExampleInterfaceDefiniFon.enumPhoneType{MOBILE 0;HOME 1;WORK 2;}messagePhoneNumber{requiredstringnumber 1;opFonalPhoneTypetype 2[default HOME];}messagePerson{requiredintid 1;opFonalstringemail 3;repeatedPhoneNumberphone honeNumber);}

LanguageIndependentMiddleware CORBA:– respecificaFon(Specis700 pages)– Aher20years,sFllprobablythemostfeature- ‐rich: xTypeSystem,ComponentSystem,Interceptors,etc.– aFble.– Mostlyusedinlargeenterprisesfromthepre- ‐webdays.

GoogleProtobuf&FacebookThrih Verysimpleandcleantypesystem alizaFonlibrarypluslightweightRPC nprogramminginC. doesnotincludeRPC.Facebook’sdoes. dverbosetext.

ICE Middleware framework:Thinkprotobufplustwisted. Opensourcebutdevelopedbyacompany. ameworkisquitereachandwell- ‐organized(developedbysomeCORBAdevelopers) traversal,eventdistribuFon,faulttolerance. HasnaFveobjecFveCsupportforiPod/iPhone!!!

Overview Low- sgrowinginpopularitySomecoolacademicwork

Cool“new”languages Scala,ObjecFveC,Erlang:– orssendingmessagetoeachother.– CannaturallyrunonmulF- program.– InScala:event- ythesame!(alotofJVMhacking) Go:– sRPClibraryaspartofstd.

CopyingaDirectoryoverFTPinErlang:publish(Host, User, Password, LocalDir, RemoteDir) - case ftp:open(Host) of{ok, Pid} - case ftp:user(Pid, User, Password) ofok - case ftp:cd(Pid, RemoteDir) ofok - case file:list dir(LocalDir) of{ok, Files} - lists:foreach(fun(I) - publish(I, LocalDir, Pid)end, Files);{error, } - exit({bad,local,directory, LocalDir})end;{error, Reason} - rror, Reason} - exit({cannot, login, as, User, reason, Reason})end;{error, Reason} - exit({cannot,connect,to,Host, reason, Reason})

Overview Low- sgrowinginpopularitySomecoolacademicwork

CurrentResearch Arangeofsystemsthattrytomarryevent- ‐basedandthreadedprogramming:– ScalaisanacFveresearchproject!– Libasync programintoanevent- usonecallbacks! age/support.

tamed static void send n rpc(str host, int port) {tvars {vector int status codes;int fd, n 5;}// Blocking call to connecttwait { tcpconnect(host, port, mkevent(fd)); } // n blocking rpc calls in parallel!!!// Change for and twait to make them sequential!twait {for (i 0; i n; i ) {client struct- call(EX RANDOM,mkevent(status codes[i]));}}// check for n-fold success using status codes

CurrentResearch D,P): link(@S,D),P (S,D)path(@S,D,P): link(@Z,S),path(@Z,D,P’),P [S,P’]

Message(Passing(vs(RPC(Message/Passing/ RPC/ n(some