Protocoles… compléments php FTP Courrier: smtp pop imap… DNS P2P 2: Application Layer
Compléments: php php est un langage de script pour les serveurs webs de nombreuses fonctions permettent de traiter les requêtes http ici on est du côté du serveur… 2: Application Layer
Exemple simple <HTML> <HEAD> <TITLE>Exemple très simple</TITLE> </HEAD> <BODY> <H1>Exemple</H1> le <?php echo Date ("j/m/Y à H:i:s"); ?> <P> <?php echo "Client :" . $_SERVER['HTTP_USER_AGENT'] . "<BR>"; echo "Adresse IP client:".$_SERVER['REMOTE_ADDR']."<BR>"; echo "Server: " . $_SERVER['SERVER_NAME']; ?> </BODY></HTML> 2: Application Layer
Résultat Exemple le 8/11/2006 à 15:54:29 Client :Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1) Adresse IP client:127.0.0.1 Server: localhost 2: Application Layer
Reçu par le client <HTML> <HEAD> <TITLE>Exemple très simple</TITLE> </HEAD> <BODY> <H1>Exemple</H1> le 8/11/2006 à 15:54:29 <P> Client :Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1)<BR>Adresse IP client:127.0.0.1<BR>Server: localhost </BODY></HTML> 2: Application Layer
Php On est ici côté serveur: Mais surtout php permet les balises <?php ?> sont interprétées par le serveur (apache par exemple) et servent à générer la page html reçu par le client Mais surtout php permet d'accéder aux variables d'environnement d'utiliser de nombreuses fonctionsalités sessions, paramètres etc. Php sert souvent d'interface pour MySql serveur simple de bases de données 2: Application Layer
Php pas de typage ni de déclaration des variables $v est remplacé par la valeur de v (et permet aussi l'affectation) echo "$v"; constantes define("PI", 3.1415); types des variables numériques $i=1; $v=3.14; chaînes de caractères (expressions régulières) $nom="Hugues"; ',",{} 2: Application Layer
php tableaux indicés associatifs next() prev() key() current() $tab[0]="un"; $tab=array("un","deux","trois"); associatifs $m=array("un"=>"one", "deux"=>"two"); $m["trois"]="three"; next() prev() key() current() do {echo "Clé=key($m).Valeur= current($m)"} while(next($mes)); foreach($m as $cle =>$val) {echo "Clé=$cle.Valeur=$val";} 2: Application Layer
Php structures de contrôles if if else while do while for foreach break, continue 2: Application Layer
fonctions function Nom([$arg1, $arg2, ...]) { } corps } passage par valeur (et pas références &) exemples function Add($i,$j){ $somme= $i + $j; return $somme; function Add($i,$j,&$somme){ 2: Application Layer
divers variables classes et objets automatiques (locales) statiques (comme en C) globales classes et objets 2: Application Layer
Pour le serveur… tableaux associatifs prédéfinis $_SERVER: environnement serveur REQUEST_METHOD QUERY_STRING CONTENT_LENGTH SERVER_NAME PATH_INFO HTTP_USER_AGENT REMOTE_ADDR REMOTE_HOST REMOTE_USER REMOTE_PASSWORD 2: Application Layer
Suite Autres tableaux $_ENV : environnement système $_COOKIE $_GET $_POST $_FILES $_REQUEST (variables des 4 précédents $_SESSION $GLOBALS les variables globales du scritp 2: Application Layer
Cookies et php <?php // Est-ce que le Cookie existe ? if (isSet($_COOKIE['compteur'])) { $message = "Vous êtes déjà venu {$_COOKIE['compteur']} fois " . "me rendre visite<BR>\n"; // On incrémente le compteur $valeur = $_COOKIE['compteur'] + 1; } else // Il faut créer le cookie avec la valeur 1 $message = "Bonjour, je vous envoie un cookie<BR>\n"; $valeur = 1; // Envoi du cookie SetCookie ("compteur", $valeur); ?> 2: Application Layer
Cookies et php (fin) <HTML><HEAD> <TITLE>Les cookies</TITLE> </HEAD> <BODY> <H1>Un compteur d'accès au site avec cookie</H1> <?php echo $message; ?> </BODY></HTML> 2: Application Layer
En utilisant les sessions <?php // La fonction session_start fait tout le travail session_start(); ?> <HTML><HEAD> <TITLE>Les cookies</TITLE> </HEAD> <BODY> <H1>Un compteur d'accès au site avec Session</H1> 2: Application Layer
Fin <?php if (!isSet($_SESSION['cp'])) { $_SESSION['cp']=1; echo "C'est la première fois, votre id est:".session_id()."<BR>"; } else{ $_SESSION['cp']++; echo "C'est votre ".$_SESSION['cp']." n-ième connexion"; if($_SESSION['cp']>10){ echo "on vous a trop vu"."<BR>"; session_destroy(); ?> </BODY></HTML> 2: Application Layer
session session_start() session_destroy() session_id() on peut associer des variables à la session par le tableau associatif $_SESSION elle sera accessible à chaque session_start() jusqu'au session_destroy() pour toute connexion qui fournit le session_id(). 2: Application Layer
FTP: the file transfer protocol user interface client file transfer FTP server user at host local file system remote file system transfer file to/from remote host client/server model client: side that initiates transfer (either to/from remote) server: remote host ftp: RFC 959 ftp server: port 21 2: Application Layer
FTP: separate control, data connections client server TCP control connection port 21 TCP data connection port 20 FTP client contacts FTP server at port 21, specifying TCP as transport protocol Client obtains authorization over control connection Client browses remote directory by sending commands over control connection. When server receives a command for a file transfer, the server opens a TCP data connection to client After transferring one file, server closes connection. Server opens a second TCP data connection to transfer another file. Control connection: “out of band” FTP server maintains “state”: current directory, earlier authentication 2: Application Layer
FTP commands, responses Sample commands: sent as ASCII text over control channel USER username PASS password LIST return list of file in current directory RETR filename retrieves (gets) file STOR filename stores (puts) file onto remote host Sample return codes status code and phrase (as in HTTP) 331 Username OK, password required 125 data connection already open; transfer starting 425 Can’t open data connection 452 Error writing file 2: Application Layer
Electronic Mail Three major components: SMTP SMTP SMTP user agents user mailbox outgoing message queue user agent Three major components: user agents mail servers simple mail transfer protocol: SMTP User Agent a.k.a. “mail reader” composing, editing, reading mail messages e.g., Eudora, Outlook, elm, Netscape Messenger outgoing, incoming messages stored on server mail server user agent SMTP mail server user agent SMTP mail server SMTP user agent Aka also known as user agent user agent 2: Application Layer
Electronic Mail: mail servers user agent Mail Servers mailbox contains incoming messages for user message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages client: sending mail server “server”: receiving mail server mail server user agent SMTP mail server user agent SMTP mail server SMTP user agent user agent user agent 2: Application Layer
Electronic Mail: SMTP [RFC 2821] uses TCP to reliably transfer email message from client to server, port 25 direct transfer: sending server to receiving server three phases of transfer handshaking (greeting) transfer of messages closure command/response interaction commands: ASCII text response: status code and phrase messages must be in 7-bit ASCII 2: Application Layer
Scenario: Alice sends message to Bob 1) Alice uses UA to compose message and “to” bob@someschool.edu 2) Alice’s UA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bob’s mail server 4) SMTP client sends Alice’s message over the TCP connection 5) Bob’s mail server places the message in Bob’s mailbox 6) Bob invokes his user agent to read message mail server mail server 1 user agent user agent 2 3 6 4 5 2: Application Layer
Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr> S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu> S: 250 bob@hamburger.edu ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection 2: Application Layer
Try SMTP interaction for yourself: telnet servername 25 see 220 reply from server enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) 2: Application Layer
SMTP: final words Comparison with HTTP: SMTP uses persistent connections SMTP requires message (header & body) to be in 7-bit ASCII SMTP server uses CRLF.CRLF to determine end of message Comparison with HTTP: HTTP: pull SMTP: push both have ASCII command/response interaction, status codes HTTP: each object encapsulated in its own response msg SMTP: multiple objects sent in multipart msg 2: Application Layer
Mail message format header body SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: header lines, e.g., To: From: Subject: different from SMTP commands! body the “message”, ASCII characters only header blank line body 2: Application Layer
Message format: multimedia extensions MIME: multimedia mail extension, RFC 2045, 2056 additional lines in msg header declare MIME content type From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data ..... ......................... ......base64 encoded data MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data 2: Application Layer
MIME Multipurpose Internet Mail Extensions texte en caractères non US ASCII attachements messages en plusieurs parties défini dans l'entête du mail à l'origine pour le mail uniquement mais utilisé de plus en plus fréquemment (exemple HTTP) SMTP ne considère que des caractères ASCII 7 bits d'où la nécessité de codage décodage 2: Application Layer
MIME Un message peut être en plusieurs parties (multipart) définies par l'entête "Content-Type" exemple Content-Type: text/plain L'entête d'un message peut contenir autre chose que du US ASCII (par exemple dans le champ SUBJECT: "=?charset?encoding?encoded text?=". Subject: =?utf-8?Q?=C2=A1Hola,_se=C3=B1or!?= (Subject: ¡Hola, señor!) 2: Application Layer
MIME Exemple de multipart Message: Content-type: multipart/mixed; boundary="frontier" MIME-version: 1.0 This is a multi-part message in MIME format. --frontier Content-type: text/plain This is the body of the message. Content-type: application/octet-stream Content-transfer-encoding: base64 PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgAVGhpcyBpcyB0aGUgYm9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg== --frontier-- 2: Application Layer
Mail access protocols SMTP SMTP access protocol user agent user agent sender’s mail server receiver’s mail server SMTP: delivery/storage to receiver’s server Mail access protocol: retrieval from server POP: Post Office Protocol [RFC 1939] authorization (agent <-->server) and download IMAP: Internet Mail Access Protocol [RFC 1730] more features (more complex) manipulation of stored msgs on server HTTP: Hotmail , Yahoo! Mail, etc. 2: Application Layer
POP3 protocol authorization phase C: list transaction phase, client: S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on authorization phase client commands: user: declare username pass: password server responses +OK -ERR transaction phase, client: list: list message numbers retr: retrieve message by number dele: delete quit C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> C: dele 1 C: retr 2 C: dele 2 C: quit S: +OK POP3 server signing off 2: Application Layer
POP3 (more) and IMAP More about POP3 IMAP Previous example uses “download and delete” mode. Bob cannot re-read e-mail if he changes client “Download-and-keep”: copies of messages on different clients POP3 is stateless across sessions IMAP Keep all messages in one place: the server Allows user to organize messages in folders IMAP keeps user state across sessions: names of folders and mappings between message IDs and folder name 2: Application Layer
DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams “name”, e.g., ww.yahoo.com - used by humans Q: map between IP addresses and name ? Domain Name System: distributed database implemented in hierarchy of many name servers application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function, implemented as application-layer protocol complexity at network’s “edge” 2: Application Layer
DNS Why not centralize DNS? DNS services single point of failure traffic volume distant centralized database maintenance doesn’t scale! DNS services Hostname to IP address translation Host aliasing Canonical and alias names Mail server aliasing Load distribution Replicated Web servers: set of IP addresses for one canonical name 2: Application Layer
Distributed, Hierarchical Database Root DNS Servers com DNS servers org DNS servers edu DNS servers poly.edu DNS servers umass.edu yahoo.com amazon.com pbs.org Client wants IP for www.amazon.com; 1st approx: Client queries a root server to find com DNS server Client queries com DNS server to get amazon.com DNS server Client queries amazon.com DNS server to get IP address for www.amazon.com 2: Application Layer
DNS: Root name servers contacted by local name server that can not resolve name root name server: contacts authoritative name server if name mapping not known gets mapping returns mapping to local name server b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 17 other locations) i Autonomica, Stockholm (plus 3 other locations) k RIPE London (also Amsterdam, Frankfurt) m WIDE Tokyo a Verisign, Dulles, VA c Cogent, Herndon, VA (also Los Angeles) d U Maryland College Park, MD g US DoD Vienna, VA h ARL Aberdeen, MD j Verisign, ( 11 locations) 13 root name servers worldwide 2: Application Layer
TLD and Authoritative Servers Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. Network solutions maintains servers for com TLD Educause for edu TLD Authoritative DNS servers: organization’s DNS servers, providing authoritative hostname to IP mappings for organization’s servers (e.g., Web and mail). Can be maintained by organization or service provider 2: Application Layer
Local Name Server Does not strictly belong to hierarchy Each ISP (residential ISP, company, university) has one. Also called “default name server” When a host makes a DNS query, query is sent to its local DNS server Acts as a proxy, forwards query into hierarchy. 2: Application Layer
authoritative DNS server Example root DNS server 2 Host at cis.poly.edu wants IP address for gaia.cs.umass.edu 3 TLD DNS server 4 5 local DNS server dns.poly.edu 7 6 1 8 authoritative DNS server dns.cs.umass.edu requesting host cis.poly.edu gaia.cs.umass.edu 2: Application Layer
authoritative DNS server Recursive queries requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server 3 recursive query: puts burden of name resolution on contacted name server heavy load? iterated query: contacted server replies with name of server to contact “I don’t know this name, but ask this server” 2: Application Layer
DNS: caching and updating records once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time TLD servers typically cached in local name servers Thus root name servers not often visited update/notify mechanisms under design by IETF RFC 2136 http://www.ietf.org/html.charters/dnsind-charter.html 2: Application Layer
RR format: (name, value, type, ttl) DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) Type=A name is hostname value is IP address Type=CNAME name is alias name for some “canonical” (the real) name www.ibm.com is really servereast.backup2.ibm.com value is canonical name Type=NS name is domain (e.g. foo.com) value is hostname of authoritative name server for this domain Type=MX value is name of mailserver associated with name 2: Application Layer
DNS protocol, messages DNS protocol : query and reply messages, both with same message format msg header identification: 16 bit # for query, reply to query uses same # flags: query or reply recursion desired recursion available reply is authoritative 2: Application Layer
DNS protocol, messages Name, type fields for a query RRs in response to query records for authoritative servers additional “helpful” info that may be used 2: Application Layer
Inserting records into DNS Example: just created startup “Network Utopia” Register name networkuptopia.com at a registrar (e.g., Network Solutions) Need to provide registrar with names and IP addresses of your authoritative name server (primary and secondary) Registrar inserts two RRs into the com TLD server: (networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A) Put in authoritative server Type A record for www.networkuptopia.com and Type MX record for networkutopia.com How do people get the IP address of your Web site? 2: Application Layer
P2P file sharing Alice chooses one of the peers, Bob. File is copied from Bob’s PC to Alice’s notebook: HTTP While Alice downloads, other users uploading from Alice. Alice’s peer is both a Web client and a transient Web server. All peers are servers = highly scalable! Example Alice runs P2P client application on her notebook computer Intermittently connects to Internet; gets new IP address for each connection Asks for “Hey Jude” Application displays other peers that have copy of Hey Jude. 2: Application Layer
Pair à pair quelques principes applications les nœuds offrent des fonctionnalités identiques (pair) volatilité importante (apparition/disparition) grande échelle et dispersion géographique dynamicité importante applications partage de fichiers messagerie téléphone (Skype) … différent du client-serveur 2: Application Layer
Partage de fichiers Communication basée sur deux types de protocoles différents découverte et localisation des fichiers recherche des données mettre en contact deux (ou plusieurs) utilisateurs parmi des millions téléchargement des fichiers 2: Application Layer
Découverte-localisation Base publication des fichiers partagés avec des méta-données découverte des fichiers disponibles localisation des sources à télécharger (En plus identification des doublons détection des fichiers corrompus forums) 2: Application Layer
Architecture du réseau Centralisée: un serveur ou un cluster sur lequel les clients se connectent (Napster) Décentralisée: il n'y a que des clients (Gnutella) Faiblement centralisée: des clients et des serveurs (Edonkey) Hybride: les clients peuvent devenir des serveurs 2: Application Layer
P2P: centralized directory directory server peers Alice Bob 1 2 3 original “Napster” design 1) when peer connects, it informs central server: IP address content 2) Alice queries for “Hey Jude” 3) Alice requests file from Bob 2: Application Layer
P2P: problems with centralized directory Single point of failure Performance bottleneck Copyright infringement file transfer is decentralized, but locating content is highly centralized 2: Application Layer
Query flooding: Gnutella fully distributed no central server public domain protocol many Gnutella clients implementing protocol overlay network: graph edge between peer X and Y if there’s a TCP connection all active peers and edges is overlay net Edge is not a physical link Given peer will typically be connected with < 10 overlay neighbors 2: Application Layer
Gnutella: protocol Query message sent over existing TCP connections File transfer: HTTP Query message sent over existing TCP connections peers forward Query message QueryHit sent over reverse path Query QueryHit Scalability: limited scope flooding 2: Application Layer
Gnutella: Peer joining Joining peer X must find some other peer in Gnutella network: use list of candidate peers X sequentially attempts to make TCP with peers on list until connection setup with Y X sends Ping message to Y; Y forwards Ping message. All peers receiving Ping message respond with Pong message X receives many Pong messages. It can then setup additional TCP connections Peer leaving: see homework problem! 2: Application Layer
Exploiting heterogeneity: KaZaA Each peer is either a group leader or assigned to a group leader. TCP connection between peer and its group leader. TCP connections between some pairs of group leaders. Group leader tracks the content in all its children. 2: Application Layer
KaZaA: Querying Each file has a hash and a descriptor Client sends keyword query to its group leader Group leader responds with matches: For each match: metadata, hash, IP address If group leader forwards query to other group leaders, they respond with matches Client then selects files for downloading HTTP requests using hash as identifier sent to peers holding desired file 2: Application Layer
KaZaA tricks Limitations on simultaneous uploads Request queuing Incentive priorities Parallel downloading 2: Application Layer
Recherche par diffusion simple les clients ne publient rien et ne font que des requêtes une requête est diffusée à tous les clients: avec une limite de portée (TTL) en évitant les cycles (identification unique de la requête, la requête contient le son chemin …) recherche en profondeur ou en largeur un client répond par le chemin emprunté par la requête 2: Application Layer
Filtres de Bloom Principe: un ensemble E de n éléments une fonction de hachage de E sur {1,m} un vecteur de m bits (le filtre) tester si x appartient à E si le bit h(x)=0 non si le bit h(x)=1 oui (mais peut être faux-positif) on peut diminuer les faux positifs en utilisant plusieurs fonctions de hachage Si le client possède le document les bits des mot-clés correspondant sont à 1 Les clients s'échangent les filtres Les requêtes ne sont propagées que vers les clients qui ont le bon filtre utilisé dans Gnutelel 2: Application Layer
Recherche par indexation Les clients publient les fichiers qu'ils partagent sur les serveurs sur lesquels ils sont connectés Les serveurs indexent les descriptions des fichiers Les clients envoient des requêtes aux serveurs pour trouver les fichiers et les localiser 2: Application Layer
Recherche par DHT Distributed hash table: On associe à chaque document (ou mot-clé) un identificateur unique On associe à chaque client un identificateur unique de même taille On définit une métrique pour définir la distance entre les identificateurs On place un document sur les k clients qui ont l'identificateur le plus proche de celui du client exemple Chord: points sur un cercle la distance est la longueur de l'arc orienté. L'espace des clés est décomposé en segments. Si i et j sont des nœuds adjacents, i a toutes les clés comprises entre i et j notion d'overlay: chaque nœud maintient des liens vers d'autres nœuds, on obtient ainsi un overlay. Comment obtenir un routage efficace? 2: Application Layer
Téléchargement protocole ad-hoc (Edonkey, Bittorrent) ou http swarming: téléchargement d'un fichier en téléchargeant différentes parties en parallèle depuis plusieurs clients téléchargement multiple le fichier est décomposé en n blocs calcule du hachage de chaque bloc fichier est identifié par le hachage des blocs 2: Application Layer
Succès… www.slyck.com June 19, 2005 - 23:00 Network Users eDonkey2K 4,379,883 FastTrack 2,482,130 Gnutella 1,598,329 Overnet 745,472 DirectConnect 294,255 MP2P 251,137 Filetopia 3,455 2: Application Layer
Quelques réseaux Napster Fasttrack (historique) Protocole: architecture centralisée recherche par indexation Fasttrack clients: Kazaa Mldonkey architecture hybride recherche par indexation et diffusion entre ultrapeers identification faible des fichiers (MD5 sur 300ko puis hachage sur 32 bits) http (+ swarming) 2: Application Layer
Quelques réseaux Edonkey Overnet/Kad Clients: Edonkeys, Emule protocole faiblement centralisée recherche par indexation TCP recherche multi-serveurs par UDP téléchargement en duplex avec bitmaps, streaming et swarming (Bittorrent dans les dernières versions) système de crédits pour inciter au partage Overnet/Kad télécharement Edonkey décentralisé DHT (Kademlia) 2: Application Layer
Quelques réseaux Gnutella Bittorrent architecture hybride Recherche par diffusion courte (TTL <8) avec filtres de Bloom Gnutella et Gnutella2 téléchargement par http avec possibilité de swarming Bittorrent pas de découverte, un fichier .torrent contient les infos sur le fichier localisation centralisée pour chaque fichier (tracker) téléchargementavec bitmaps le client commence à forunir du contenu à ses voisins au bout d'un certain temps il bloque les voisins qui ne répondent pas et conserve les quatre meilleurs 2: Application Layer
Quelques réseaux Freenet complètement distribué publication par copie recherche par diffusion en profondeur protocole et contenu cryptés documents signés par signature digitale axé sur l'anonymat 2: Application Layer