29 minute read

Application Layer

TCP/IP Protocol의 제일 user와 맞닿은 layer가 Application layer이다.

Application layer는 Internet 사용자에게 service을 제공하는 역할을 한다

Application Layer에서 사용되는 protocol은 두 가지로 나눌 수 있다.

  1. Standard Application-Layer protocol
    • Internet authority에서 공식화한 것
    • ex) HTTP, FTP, SMTP, POP3, TELNET
  2. Nonstandard Application-Layer protocol
    • Internet authority에서 공식화하지 않은 것
    • Private use only

Application Layer Paradigm

Application Layer Paradigm이란 network의 구조라고 보면 된다. 각 host는 어떻게 배치될 것이고 각자 어떤 역할을 할 것인지를 정의한 것이라고 보면 된다.

Application Layer paradigm으로는 3가지가 존재한다.

  1. Client-Server paradigm

    Client-Server paradigm은 host의 역할을 server와 client으로 나눈 것이다.

    Centralized 성격을 가진다.

    Server

    • Always on
    • Client의 요청에 대한 답변을 주는 host
    • IP address가 영원함

    Client

    • Server와 연결을 시작하는 host
    • Client들끼리 서로는 직접 통신을 하지 못하고 항상 server을 거친다

    ex) WWW (World Wide Web), FTP, Remote login (TELNET, SSH (Secure SHell)), E-mail

    joowan1108

  2. Peer-to-Peer paradigm

    모든 host의 역할이 “Peer”으로 고정되어있다.

    • No always-on server
    • 직접 통신 가능
    • Peer끼리 가끔 연결되고 IP address는 변한다
    • Highly distributed and decentralized
    • High scalability, increase service capability
    • 보수하기 어려움

    joowan1108

  3. Mixed paradigm

    Client-Server와 Peer to peer 성격을 둘 다 가진 paradigm이다.

    Client은 server로부터 정보를 가져오지만 client끼리도 정보를 주고 받을 수 있는 paradigm이다.

    ex) Nate, Yahoo messenger

Socket: Application Programming Interface of Application Layer

Application layer는 lower four layers와 정보를 주고 받기 위해 socket이라는 API (application program interface)을 사용한다.

Socket API는 application layer가 operating system과 소통하기 위해 존재한다.

이때 socket은 application program이 생성하는 data structure이다.

joowan1108

Socket을 Client-Server paradigm 관점에서 설명해보자

이 socket은 server와 client끼리 직접적인 logical connection이 존재하는 것처럼 느끼도록 해주는 역할을 한다. 즉, client는 socket이 request을 받고 response을 주는 객체라고 생각하고 server는 socket이 request을 하고 response을 받아내는 객체하고 생각하게 된다는 것이다.

joowan1108

Client와 server는 양방향의 소통을 하기 때문에 한 쌍의 address (local, remote)가 필요하다. 앞서 말했듯이 client-server paradigm은 client와 server의 socket을 통해 소통을 하기 때문에 이 address는 사실 socket address이다.

joowan1108

Server 입장

  • Server (Local) Socket Address

    $\rightarrow$ Operating System이 정해준다

    $\rightarrow$ Server가 실행되는 computer의 IP Address을 갖는다

    $\rightarrow$ Port는 server가 실행될 때 정해진다

    $\rightarrow$ Server가 실행되는 동안에는 고정된다.

  • Client (Remote) Socket Address

    $\rightarrow$ Client가 server에 접근하려고 할 때 정해진다

    $\rightarrow$ Client마다 고유하다

Client 입장

  • Client (Local) Socket Address

    $\rightarrow$ Operating System이 정해준다

    $\rightarrow$ Client가 실행되는 computer의 IP Address을 갖는다

    $\rightarrow$ Port는 client가 server에 접근하려고 할 때 정해진다

  • Server (Remote) Socket Address

    $\rightarrow$ 사용자가 IP address와 port number를 직접 정해줘야 한다. (ex) url의 domain name을 통해)

Using services of Transport layer

Application layer는 socket을 통해 나머지 layer와 연결한다고 하였다. Application layer에는 물리적인 connection이 없기 때문에 하위 layer의 service을 통해 물리적인 연결을 얻어야 한다. 다만 이 과정은 socket이 알아서 다 해주기에 application layer 자체는 알지 못하는 것이다.

그렇다면 socket은 하위 layer들과 어떻게 연결되는 것일까?

$\rightarrow$ Socket이 사용할 언어 (transport layer의 service)을 선택함으로써 socket이 transport layer와 연결할 수 있게 되는 것이다.

이 service를 transport layer protocol이라고 하고 종류는 크게 3가지이다.

  1. UDP (User Datagram Protocol)
    • Connectionless, unreliable, datagram
    • Message의 단위는 datagram으로 encapsulated된 packet이다. Message oriented
    • Connectionless: Message을 주고 받는 양끝 객체들끼리는 logical connection이 없다
    • datagram은 독립적이다. (not ordered)
    • small data usage, speed > reliability, multimedia에 적합
    • No retransmission
  2. TCP (Transmission Control Protocol)
    • Connection oriented, reliable, byte stream
    • Connection oriented: Data을 주고 받는 양끝 객체들끼리 logical connection이 이루어진다.

      $\rightarrow$ 이 connection은 handshake process을 통해 이루어진다

    • Long messages, reliability에 적합 (File transmission)
    • Stream based
    • Automatic retransmission
  3. SCTP (Stream Control Transmission Protocol)
    • Connection oriented, reliable, message oriented
    • 여러 multiple network connection을 통해 mutli-stream service가 가능하다
    • Partially ordered
    • Partially reliable

    joowan1108

    • Multi-homing: multiple IP address in one port, occurs in peer to peer
    • Multi-Streaming: 하나의 server에 multiple host 가능, occurs between client and server

Standard Client-Server Application Protocol

Client-Server paradigm을 적용한 application들과 각 application을 위한 protocol을 보자

World Wide Web protocol: HTTP

World Wide Web이란

Web은 first proposed by Tim Berners-Lee in 1989 at Conseil European pour la Recherche Nuclear (CERN)

World Wide Web은 distributed client-server service으로 browser(client)가 web server (server)로부터 web page을 얻게 해주는 service이다.

  • Browser는 server로부터 갖고 온 web page을 조회하는 client이다. Browser는 controller, client protocol, 그리고 interpreter로 구성되어 있다.

    joowan1108

  • Web server는 client가 요청한 web page을 반환하는 역할을 한다. 효율을 높이기 위해서 요청된 web page들을 cache에 보관할 때도 있다.

Web Page

Web page는 identifier으로 url(Uniform Resource Locator)이 사용되며 protocol, host(IP address of server / domain name), port (16 bit, predefined), path(Operating system에서의 위치)으로 구성된다.

protocol://host/path

protocol://host:port/path

Web page는 세 종류로 나뉜다.

  1. Static
    • fixed content
    • server에 저장되어 있고 copy만 가져가는 것임
    • Language: Hypertext Markup Language (HTML), Extensible Markup Language (XML), Extensible Style Language (XSL), and Extensible Hypertext Markup Language (XHTML)
  2. Dynamic
    • 요청 받을 때마다 web server에서 생성
    • Language: Common Gateway Interface (CGI), Java Server Pages (JSP), Active Server Pages (ASP), and ColdFusion
  3. Active
    • Client에서 실행되고 있는 프로그램
    • Language: JavaScript or Java (Applet)

World Wide Web protocol: HTTP

World Wide Web application을 사용하기 위해서는 HTTP protocol을 사용해야 한다. HTTP protocol을 통해 web server에서 web page들을 가져올 수 있는 것이다.

Server는 port number 80을 고정으로 사용하고 client는 임시 port number을 사용한다.

HTTP(Hypertext Transfer Protocol) 특징

HTTP는 TCP를 사용하고 HTTP에서 client와 server가 연결되는 방법에는 두 가지가 존재한다.

Connection Type

  1. Nonpersistent Connections

    각 request/response마다 하나의 TCP connection을 수행하는 방법이다. 하나의 request을 할 때마다 한번의 connection을 해야 하기 때문에 한 request 하기 전에 3번의 handshake을 해야 하고 response을 받으면 close을 해야 한다. Close하기 위해서는 또 3번의 handshake을 해야 한다.

    joowan1108

  2. Persistent Connections

    Persistent connection에서는 server가 response을 보내더라도 계속 connection을 유지한다.

    Connection close는 timeout이나 client의 request으로 가능하다.

    one connection establishment and one connection termination even at multiple requests

    각 response에 server는 data의 길이를 포함시킨다. 하지만 web page가 dynamic하거나 active일 때는 data의 길이가 정해져있지 않기 때문에 data의 길이에 대한 정보를 client에게 알려주기 위해 data을 다 보낸 뒤에 server을 닫는다.

    joowan1108

HTTP을 사용한 예시로 GET method와 PUT method가 있다.

  1. GET: Server에서 web page을 가져오기

    HTTP에서 request는 method 이름, URL, 그리고 사용한 http version이 포함된다.

    Header 2 lines: 받을 수 있는 데이터 형식

    Request body는 비어있다.

    GET의 response는 response의 status 정보 + 4 lines of header (date, server, content encoding, length)가 포함된다. Body에는 요청한 document가 들어있다.

  2. PUT: Server에 web page을 post하기 HTTP에서 request는 method 이름, URL, 그리고 사용한 http version, 4 lines of header가 포함된다. 또, request body에는 web page의 내용이 들어있다.

    Response message에는 response의 status 정보 + 4 lines of header가 포함된다. 생성된 document는 response body에 포함된다.

Cookies

World Wide Web의 Web server는 cookies을 통해 이전에 방문한 client들의 정보를 기억할 수 있다.

Cookies는 server가 client에게 response을 보낼 때 cookies을 생성하고 response에 포함된다.

Client에 도착한 client는 client의 cookie directory에 저장된다. 이 cookie는 client가 server에 다시 request을 전송할 때마다, cookie directory에서 호출되어 request에 포함된다.

이 과정을 통해 server가 client을 기억할 수 있게 된다.

이때, cookie의 내용은 browser나 user에게 공개되지 않고 server만 생성하고 처리할 수 있다.

Web Caching: Proxy Server

HTTP는 proxy server을 통해 최근 request들에 대한 response을 저장할 수 있다. 이 proxy server는 cache처럼 작동하여 request가 올 때 proxy server에 그 request에 대한 response을 한 적이 있는지 확인한 다음, 있다면 proxy server에서 직접 response을 전송하고 없다면 web server에서 찾는다.

$\rightarrow$ 이를 통해 web server에 부담을 줄이고, traffic 감소, improve latency (반응 속도)

Proxy server는 보통 client 측에서 저장된다. 따라서, 한 LAN 컴퓨터에 proxy server을 실행하면, LAN 안팎을 오가는 data 수를 줄일 수 있다.

이 proxy server 내용은 어떻게 update할까?

  • 일정 시간 이상 유지되는 내용은 계속 저장
  • 마지막으로 modified된 날짜를 header에 저장하여 이를 기준으로 삭제/저장

joowan1108

HTTP 진화

HTTP은 본래 static web page을 위해 디자인 된 것이지만 image/script 등 resource가 많이 필요한 web page들이 많아졌다.

따라서 bandwidth와 processing load을 늘려야 했다.

또, HTTP은 원래 sequential protocol으로 동시에 fetch을 하지 못했다.

HTTP/2

  • Binary Protocol

    기존의 HTTP는 text을 통해 header을 구성하였다. 이로 인해 parser는 header의 전체 길이를 바로 알 지 못했으며 header field들은 중복되는 내용이 많았다.

    HTTP/2의 binary protocol은 text로 표현되던 header을 binary로 표현함으로써 request와 response을 처리하는 효율과 속도를 높였다.

    joowan1108

  • Stream and multiplexing

    Makes one TCP connection into multiple streams by multuplexing

    각 request/response 쌍을 stream 값으로 identify하여 server가 client에게 여러 response를 보내더라도 각 response가 어떤 request을 위한 것인지 바로 알 수 있게 되어 response을 병렬으로 여러 개 받을 수 있게 되었다.

    joowan1108

  • Stream priority

    Client가 server에게 어떤 내용을 더 우선적으로 고려했으면 좋을 지를 보낼 수 있게 되었다. (ex: web page을 보여줄 때 HTML, CSS, JSP을 image보다 우선시해라)

    HTTP/2는 stream weight와 stream dependency을 통해 priority을 알아낸다

    joowan1108

  • Server push

    Client가 나중에 무엇을 요청할 지에 대한 사전 정보를 server가 알 수 있게 되었다.

    joowan1108

하지만 HTTP/2도 단점을 가지고 있다. HTTP는 본래 TCP 기반이기 때문에 TCP에서 packet들을 순서대로 합친 뒤 application layer에 보낸다. 하지만 HTTP/2가 제공하는 stream and multiplexing으로 인해 각 stream이 독립적으로 변한다. 아무리 request/response가 stream 값을 통해 indexing 되어 있어도 이는 application layer만 해석할 수 있는 것이고 아래 layer인 TCP는 이 정보를 알 지 못한다. 즉, TCP에게는 그저 byte stream일 뿐이다. 따라서 TCP는 이 stream 값을 활용하지 못한다. 또, TCP는 reliable한 특징을 가지고 있기 때문에 첫 번째 packet이 도착 안 한 상태에서 다른 packet들이 도착한다면, 이 packet들은 buffer에 저장되고 application layer에 보내지지 못한다. 또, 첫 번째 packet이 재전송될 때까지 모든 stream이 중지된다.

HTTP/3

HTTP/3은 Quick UDP Internet Protocol (QUIC)을 통해 이 문제를 해결한다

File Transfer Protocol: FTP

한 host에서 다른 host에게 file을 복사하기 위해 필요한 protocol이다.

HTTP을 통해서도 file을 주고받을 수 있지만 FTP는 다양한 형식의 file과 큰 용량의 file에 더 적합하다.

이때, file transfer란 셋 중 하나다.

  1. Retrieving file (server -> client)
  2. Storing file (client -> server)
  3. Directory listing (server -> client)

FTP server는 server control process와 server data process으로 구성된다. Control process끼리는 control connection을 통해, data process끼리는 data connection을 통해 연결된다.

joowan1108

두 연결 종류는 서로 다른 lifetime을 가지고 있다.

Control connection은 FTP session이 시작될 때 연결되고 session동안 계속 연결되어 있는다

반대로 Data connection은 파일 transfer 할 때마다 연결이 되고 다 보내지면 바로 closed된다.

또, 둘은 생성 과정이 다르다.

Control connection은 일반적인 Client-Server paradigm처럼 서버가 먼저 port 21에서 passive open을 하여 client가 active open을 하기까지 기다린다.

반대로 Data connection은 순서가 반대여서 client가 기다리는 역할을 한다.

Data connection의 순서는 다음과 같다.

  1. Client가 먼저 임시 ephemeral port을 통해 passive open을 시작
  2. Client가 PORT 명령어로 server에 임시 port number을 전달
  3. Server가 port 20번과 전달받은 port number을 연결하여 active open을 시작하여 실제 데이터 연결이 시작

이때, port 20과 client의 port가 연결되더라도 control connection을 통해 어떤 파일을 주고받을 지 결정된다.

joowan1108

RETR 명령어를 실행할 때만 data connection이 성립된다. 반대로 control connection은 항상 되어있다.

Email Protocol

Email은 HTTP나 FTP와 달리 one-way transaction이다. 즉, sender와 receiver가 동시에 연결 안 되어있어도 된다.

즉, sender와 receiver 모두 오직 client program만 실행하고 있어도 중간에 있는 서버들이 client-server paradigm을 통해 메세지를 전달한다는 것이다.

이 내용은 email system의 구조를 통해 알 수 있다.

joowan1108

User Agent

  • User Agent (UA)는 user에게 메일 전송 / 받기 과정을 쉽게 해주는 service을 제공한다.
  • UA는 mail의 생성, 읽기, 답장, mailbox 관리 등을 돕는 user computer에서 실행되는 프로그램이다.
  • UA는 command-driven UA (mail, pine)와 GUI-driven UA(Outlook)으로 나뉜다.

메일을 전송하기 위해서 UA는 envelope와 message(header + body)으로 구성된 형식을 생성한다.

joowan1108

이때, address는 local part와 mail server의 domain name으로 구성된다.

joowan1108

Email은 한 이름으로 다양한 Email 주소들을 표현할 수 있다. 이 기능을 mailing list이라고 한다. 이 mailing list의 모든 사람들에게 mail을 보내기 위해서는 그 사람 수만큼의 message을 만든 뒤, Message Transfer Agent (MTA)에 전송되어야 한다.

Message Transfer Agent

Email system은 세 client-server application (두 MTA application + 한 MAA application)으로 분석할 수 있다.

joowan1108

이 application들이 사용하는 protocol도 다르다. MTA client와 MTA server 간에는 SMTP (Single Mail Transfer Protocol)을 사용하고 MAA client와 MAA server 간에는 POP / IMAP을 사용한다.

SMTP는 client $\rightarrow$ server, server $\rightarrow$ server에 사용되고

POP/IMAP은 server $\rightarrow$ client에 사용된다고 보면 된다.

SMTP에서 메일 transfer 과정은 3 단계를 거쳐야 한다.

joowan1108

  1. Connection Establishment

    SMTP client가 port 25으로 TCP connection을 하여 SMTP server가 connection phase 시작

  2. Message Transfer

    Sender와 한 명 또는 여러 receiver 간의 single message 교환

  3. Connection Termination

    Email 전송 뒤에 SMTP client가 connection 끊기

Message Access Agent

POP3와 IMAP은 MAA Server로부터 MMA Client으로 email을 가져오기 위해 사용되는 protocol이다.

  • Post Office Protocol (POP3)
    • 간단하지만 제한된 기능을 가진다.
    • Client용 POP3 software는 recipient computer에 설치되고 server용 POP3 software는 메일 server에 저장된다.
    • Can only check mails using one device

    joowan1108

  • Internet Mail Access Protocol (IMAP)
    • IMAP은 Email을 다운로드 하기 전에 header를 확인하거나 내용을 검색할 수 있다.
    • IMAP은 Email을 부분적으로만 다운받을 수 있어 bandwidth가 제한되거나 multimedia가 들어있을 때 유용하다
    • Mail server에서 mailbox을 편집할 수 있다.
    • Checking mails using multiple devices is possible

MIME: Multipurpose Internet Mail Extension -> email content formatting, used for non ASCII data

Secure Shell (SSH) protocol

SSH는 remote logging과 file transfer을 위해 사용된다.

  • Remote logging: Putty, Tectia

  • File Transfer: SFTP(Secure File Transfer Program) , Secure Copy (SCP)

SSH는 client와 server 사이에 안전한 연결 서비스를 제공하는 protocol이다.

  • Port Forwarding

    SSH에서 제공하는 secured channels을 이용하여 보안 기능이 없는 application에 안전하게 접근할 수 있다.

    Port forwarding은 다른 protocol에 해당되는 site 사이에 tunnel을 생성한다고 이해할 수 있다.

    TELNET, FTP, Simple Mail Transfer Protocol도 port forwarding을 사용한다.

    joowan1108

Domain Name System (DNS) protocol

TCP/IP Protocol은 IP 주소를 통해 Internet의 host을 알아낸다. 이때 Internet을 쉽게 사용할 수 있도록 domain/host name과 IP 주소를 mapping한다.

하지만, host 수가 너무 많기에 하나의 중앙 system으로 모든 IP 주소와 name들을 mapping 해놓은 정보를 다 저장할 수 없다. 따라서, 이 mapping 정보들을 분배했는데 이 방법을 사용하는 system을 Domain Name System (DNS)라고 한다.

joowan1108

각 name을 IP address에 mapping하는 방법은 크게 두 가지로 나뉜다.

  1. Flat name space

    • 특별한 구조 없이 name과 address을 1대1 대응시킨 것
    • 중복과 모호성을 방지하기 위해 central system 관리가 요구되기 때문에 Internet처럼 큰 system에 사용될 수 없음 (Centralized 되어야 함)
  2. Hierarchical name sapce

    • 여러 독립적인 부분들이 이름을 구성하도록 만들었다. 각 부분들은 organization, department, 등의 의미를 갖는다.
    • 이 부분들을 바탕으로 정보를 분산시켰다.
    • Decentralized 가능하다

Domain Name Space

  • Hierarchical name space을 바탕으로 되어있다.
  • Inverted Tree 구조이며 128 level (0~127)까지 가질 수 있다.
  • 각 node는 label (최대 63 글자)을 가지며 고유해야 한다.
  • Root node는 null label이다.
  • 각 node는 domain name을 가지고 domain name은 root부터 자기까지의 labels들을 ‘.‘으로 연결한 형태이다
  • Full domain name은 root부터 자기까지 읽는 것이다. Root의 domain name은 null이기에 full domain name은 항상 ‘.‘으로 끝난다

Fully Qualified Domain Name (FQDN)

host name과 full domain name으로 구성된 Host의 완성형 domain name이다.

joowan1108

이때, Domain이란 그냥 domain name space의 subtree이고 domain name은 substree 맨 위 node의 name이다.

DNS는 domain name과 IP 주소 mapping 정보를 많은 서버들이 갖게 하고 Domain name space처럼 서버들로 tree으로 구성하여 mapping 정보를 distribute하는 것이다. 이 서버를 DNS 서버라고 한다.

각 DNS 서버가 각자의 영역을 관리하는 역할을 하도록 하여 decentralized system을 만드는 것이다.

joowan1108

이때 관리하는 영역을 Zone이라고 한다.

처음에는 한 서버의 domain과 zone은 같은 영역이지만, DNS 서버가 domain의 일부를 다른 서버에게 관리 권한을 넘겼다면, 그 부분은 더 이상 zone이 아니기에 그때부터는 domain과 zone은 다른 부분을 지칭하게 된다.

joowan1108

Root server는 전체 tree를 zone으로 두는 server이다. Root server는 mapping 정보를 지니지는 않고 서버들에게 자신의 권한을 나눠주는 server으로 보면 된다. Root server는 여러 개가 존재할 수 있으며 전체적으로 분배되어 있다.

DNS server 종류

  1. Primary server

    • Zone 파일을 생성, 유지, 업데이트하는 역할을 하는 서버로, disk으로부터 모든 정보를 가져온다
  2. Secondary server

    • 다른 서버 (Primary, Secondary)로부터 zone에 대한 정보를 복사하여 전달, 저장하는 역할을 하는 서버로 primary server로부터 정보를 가져온다.

    • 자기의 local disk에 정보를 저장한다.

DNS Domain 종류

Internet에서 DNS는 원래 generic, country, inverse domain으로 나뉘어져 있었지만 inverse domain은 deprecated 되었다.

Inverse domain은 IP address가 주어졌을 때 domain name을 알려주는 역할을 한다

  1. Generic domain

    Host의 generic behavior에 따라 분류되었다. 각 node는 하나의 domain을 정의한다.

    joowan1108

  2. Country domain 따른 두자리 글자로 국가를 나타내어 국가에 따라 domain을 분류하였다.

    joowan1108

Resolution

Name을 IP Address에 mapping하는 과정을 name-address resolution이라고 한다.

예를 들어 some.anet.com host의 어떤 application이 메세지를 보내기 위해 engineering.mcgraw-hill.com의 IP Address을 찾고 있는데 anet.com의 DNS server가 이 IP Address에 대한 정보가 없다고 해보자

이 IP Address을 찾는 방법은 크게 2가지가 존재한다.

  1. Recursive Resolution

    이 IP Address을 모르는 각 server는 이 address을 가질만한 server에 recursive하게 요청 (query)을 보내는 방법이다.

    IP address을 찾았다면, 그 결과는 지금까지 query을 보낸 server들의 경로대로 local server에게 전달된다.

    이 IP Address을 모른다면 모두 이 address을 찾아야 하는 책임을 갖게 된다고 보면 된다.

    each server that does not know the mapping takes the responsibility for recursively querying the appropriate server to find out the IP address of the destination host

    Finally, the result is recursively sent back to the client through the chain of servers being queried previously

    마치 DFS 같다

    joowan1108

  2. Iterative Resolution

    IP address을 모른다면 모른다고 local server에게 답변을 하는 방법이다. 따라서 local server는 address을 찾을 때까지 다른 DNS server들에게 query을 보낸다.

    IP Address을 찾아야 하는 책임은 오직 local server에게 있다고 보면 된다.

    joowan1108

$\rightarrow$ 이 resolution 과정을 빠르게 하기 위해서 Caching을 사용할 수 있다.

서버가 다른 서버에게 mapping을 받았을 때, 이를 cache memory에 저장시켜서 나중에 동일한 query가 왔을 때 빠르게 mapping 정보를 반환할 수 있게 된다.

하지만 caching에는 시간이 지나 실제 정보와 달라질 수도 있다.

이 문제를 방지하기 위해 time to live (TTL)을 정해서 cached mapping 값이 정확한지 알 수 있게 하였다. (TTL은 받은 IP 주소에 해당되는 도메인의 관리 서버가 알려주는 것이고 정보를 받은 server는 TTL counter로 TTL이 지났는지 확인하는 것이다)

DNS server에서 Zone 정보는 **Resource Record**라는 tuple로 저장한다. (Domain name, type, class, TTL, value)

  • Domain name: 가리키는 domain name

  • Value: Domain name에 대한 IP Address

  • TTL: 정보의 유효 기간

  • Class: 네트워크 타입 (IN: INTERNET)

  • Type: 데이터 종류

DNS Resolver

Resolver는 DNS Client라고 생각하면 된다. UNIX와 Windows에서는 nslookup을 사용한다.

ex) nslookup www.forouzan.biz –> name과 IP Address을 준다

DNS는 UDP, TCP 모두 사용할 수 있는데 UDP는 response 크기가 512 bytes 이하일 때 사용하고 TCP는 response 크기가 512 bytes 이상일 때 사용된다.

Port는 모두 53을 사용한다

Peer to Peer Network (P2P)

P2P는 모든 host가 client와 server 모두 될 수 있는 paradigm이다.

P2P는 구조를 기준으로 두 가지로 분류할 수 있다.

  1. Centralized

    Centralized P2P는 중앙 directory system이 사용된다. Directory system은 현재 Network에 존재하는 peer와 각 peer가 어떤 파일을 가지고 있는지에 대한 정보를 갖고 있다. 이 directory system만 client-server paradigm을 사용하고 peer끼리 파일을 공유할 때는 P2P paradigm을 사용한다.

    joowan1108

  2. Decentralized

    Directory system 없이 peer 자체가 overlay network을 사용하여 각 peer에게 파일을 공유한다. (Overlay network는 physical network 위에 만들어진 logical network)

    Overlay network을 통해 P2P는 다른 identifier을 사용하여 IP Address을 알지 못하더라도 overlay network 상에서 주변 peer으로부터 원하는 파일을 갖고 있는 peer가 누군지 알아낼 수 있다.

    Decentralized P2P는 두 가지로 나뉜다.

    • Unstructured

      노드들이 랜덤하게 연결되어 있기에 검색이 비효율적이다. (query request가 목표를 찾을 때까지 계속 흘러다녀야 하기 때문) $\rightarrow$ Traffic이 나쁨

      ex) Gnutella, Freenet

    • Structured

      노드들이 규칙에 따라 연결되어있어서 query가 효율적으로 처리된다. 사용되는 규칙을 Distributed Hash Table (DHT)라고 한다.

      ex) BitTorrent

Distributed Hash Table (DHT)

DHT는 P2P의 노드들을 배치하는 규칙이다.

Identifier(Node ID)에 사용하는 bit 크기가 m일 때, 각 data item과 peer를 $2^m$ 크기의 address space에 identify한다. 이때 사용되는 identifier는 두 가지이다.

  1. Hashing Peer Identifier Node ID = Hash(Peer IP Address)

  2. Hashing Object Identifier key = Hash(Data item)

Node 5가 파일 “Liberty”를 공유하고 싶다고 했을 때, 그 파일 “Liberty”에 접근하기 위해 필요한 정보는 시계 방향에서 파일 “Liberty”의 key와 가장 가까운 node 안에 저장한다.

joowan1108

이때, DHT을 적용하기 위해서는 각 노드에 특정 파일에 접근하려 할 때 방문해야 하는 노드가 무엇인지 알려주는 정보 (Routing table)가 들어있어야 한다. 또, P2P에서는 peer가 software을 시작하면 network에 참여하게 되고 software을 끄면 network에 나가게 되므로 node의 추가/삭제가 효율적으로 되어야 한다.

DHT을 구현하는 protocol은 총 세 가지이다: Chord, Pastry (제외), Kademlia

Chord

Chord의 identifier space 크기는 $2^m$ 으로 시계 방향으로 분배한다.

Identifier 크기는 0~$2^m -1$ 이다.

k의 Successor란 N $\ge$ k을 만족하면서 가장 가까운 peer이다. k의 successor가 k에 접근에 대한 정보를 지니고 있다. k의 successor는 k을 지니고 있는 peer와 같은 것이 아니다.

Routing Table

Chord에서 각 노드는 query key의 successor을 찾도록 도울 수 있는 정보가 저장되어 있어야 한다. 즉, 각 노드는 routing table을 갖고 있어야 하며 이 table을 finger table이라고 부른다.

각 노드의 finger table에는 자신의 m 개의 successor에 대한 정보가 들어있다.

joowan1108

Target key는 이동하고 싶은 위치, successor of target key는 이 key 위치에 대한 정보를 갖고 있는 노드로 이해하면 된다.

여기에 추가로 하나의 predecessor을 저장한다.

joowan1108

joowan1108

joowan1108

찾고자 하는 key의 reference 정보를 가지고 있는 노드를 찾기 위해서는 key의 predecessor을 구한 뒤에 그 predecessor의 successor을 찾으면 된다. 그 노드가 곧 key의 successor (key의 reference 정보를 가지고 있는 노드)이기 때문이다.

Node 5에서 K14을 찾으려고 한다고 하자

  1. Node 5의 finger table에서 k14에 가장 가까운 predecessor을 찾는다 (N10)

  2. N10으로 이동

  3. N10에서 다시 k14에 가장 가까운 predecessor을 찾는다. (N12)

  4. N12로 이동

  5. N12의 finger table에서 k14의 predecessor가 없음 $\rightarrow$ N12가 k의 predecessor

  6. 그렇다면 N12의 successor가 k14의 successor $\rightarrow$ N12의 finger table의 맨 위에 있는 노드, 즉 시계방향에서 가장 가까운 노드가 N12의 successor이며 k14의 successor이다. (N20)

Kademlia

Kademlia는 두 노드 간의 거리를 바탕으로 routing을 한다.

거리는 XOR operation으로 측정한다. ex) $12 = (1100)_2$ XOR $11 = (1011)_2$ 사이의 거리는 $7 = (0111)_2$이다.

Kademlia protocol에서 key는 최대한 같은 subtree에 존재하면서 거리가 가장 가까운 노드에 저장된다.

Identifier가 m bits으로 되어있다면 전체 tree 높이도 m이다.

joowan1108

Routing Table

Kademlia도 마찬가지로 노드마다 총 m행의 routing table을 가지고 있다. 각 행은 노드의 subtree에 해당된다.

joowan1108

Subtree(row) i에는 node의 길이 i prefix와 같은 node들이 들어간다. Node가 여러개라면 거리가 가장 가까운 node가 들어간다

joowan1108

예를 들면, m=4일 때 N6 $(0110)_2$의 finger table의 row 0의 후보로는 N15 $(1111)_2$, N8 $(1000)_2$, N11 $(1011)_2$ 이 있지만 가장 가까운 N은 N15이기에 finger table의 row 0에는 N15가 들어가게 된다.

Kademlia에서 key에 대한 reference 정보를 찾는 방법은 다음과 같다.

m=4이고 N0에게 k12가 어디 있는지 query을 주었다고 해보자

joowan1108

  1. N0(0000)은 k12(1100)와 common prefix length가 0이다.
  2. N0의 routing table row 0에 들어있는 노드로 간다. (N8)
  3. N8(1000)와 k12(1100)와 common prefix length는 1이다.
  4. N8의 routing table row 1에 들어있는 노드로 간다. (N15)
  5. N15(1111)와 k12(1100)와 common prefix legnth는 2이다.
  6. N15의 routing table의 row 2에는 아무 node가 들어있지 않다.
  7. N15가 k12에 대해 responsible하다.

K-bucket

Kademlia는 query 처리 효율을 높이기 위해서 한 row에 들어가는 node 최대 개수 (k-bucket)을 1보다 늘릴 수 있다. 보통 20

k-bucket을 키우면 얻는 이점은 다음과 같다.

  1. P2P에서 peer의 출입은 자유롭기 때문에 한 node의 routing table에 들어있는 node가 이미 network에 연결이 안 되어있을 수 있다.

    $\rightarrow$ Routing table의 한 노드에 여러 노드를 저장함으로써 row에 들어있는 첫 node가 disconnect 되어도 대책이 존재한다.

  2. Parallel Query: K-bucket 수만큼의 parallel query을 보낼 수 있다. 이를 통해 접근이 fail되는 node는 버리고 나머지 노드들로 query을 처리할 수 있다.

  3. Concurrent Updating: Routing table의 update에도 좋다. 한 노드로 여러 개의 query을 보냈는데 답장을 못 받았다면, 그 노드 정보를 routing table에서 제거할 수 있는 근거가 된다.

Kademlia protocol을 적용하는 Peer to peer network에 연결되기 위해서는 하나의 peer을 알고있어야 한다. 알고 있는 peer에게 자신의 identifier을 보냄으로써 k-bucket이 형성된다.

Peer to peer network에서 나갈 때는, concurrent updating을 통해 자동으로 update 된다.

BitTorrent

Decentralized Peer to peer의 대표적인 application은 BitTorrent이다.

File sharing은 torrent라는 process을 통해 수행된다.

Torrent에 참여하는 각 peer들은 다른 peer들로부터 file chunk을 다운받고 그 chunk을 다른 peer들에게도 공유한다.

Torrent 내의 peer들을 swarm이라고도 부른다. 이 swarm 안에서 peer는 두 분류로 나뉜다.

  1. Seed: 전체 파일을 가지고 있는 peer
  2. Leech: 일부 파일만 가지고 있으며 나머지 파일을 다운받고 싶어하는 peer

BitTorrent with Tracker

BitTorrent는 본래는 centralized 성격도 가진 application 이었다.

Tracker라는 중심 노드 (server)를 사용하여 peer간의 통신을 도왔다.

Peer는 file을 다운받기 위해서는 torrent file이라는 것을 갖고 있어야 한다. Torrent file이란 특정 torrent을 관리하는 tracker의 주소와 content file의 일부를 의미한다. Peer는 다운받기 위해서 Tracker에 torrent의 peers에게 정보를 얻어내달라고 요청을 보냈다.

joowan1108

BitTorrent without Tracker

Tracker의 역할을 network의 일부 노드들이 모두 수행하도록 하여 centralized 성격을 없앴다.

DHT을 통해 필요한 torrent file metadata (key)에 responsible한 노드를 찾고 그 노드로부터 원하는 파일을 가지고 있는 peers (seed, leech)의 정보를 얻는다. 이들로부터 필요한 파일을 다운로드 받는다.

Practice problems

  1. List three non-proprietary Internet applications and the applicationlayer protocols that they use
    • World Wide Web: HTTP
    • File transfer: FTP
    • E-mail: SMTP, POP3 and IMAP (Internet Messaging Access Protocol)
  2. For a communication session between two hosts, which host is the client and which is the server?
    • WWW service: a browser is a client process and a Web server is a server process
    • P2P file sharing: the peer that is downloading the file is labeled as the client, and the peer that is uploading the file is labeled as the server
  3. What is an HTTP cookie? List some common use of cookies.
    • A cookie is a small piece of text file stored on a user’s computer in the form of a name-value pair
    • Cookies are used by websites to keep track of visitors. The most common example of using a cookie is to store User information, User preferences, Password Remember Option, etc
  4. Why is it said that FTP sends control information “out of band”?
    • Because the control information is not sent over the same connection that the file is sent over, FTP sends control information out of the band
  5. Provide the full name of the acronyms: SMTP, POP3, IMAP
    • SMTP: Simple Mail Transfer Protocol
    • POP3: Post Office Protocol version 3
    • IMAP: Internet Mail Access Protocol
  6. Consider SMTP, POP3 and IMAP. Are these stateless protocols? Why or why not?
    • All three are stateful protocols
    • They maintain store the past information for further uses:
    • SMTP: stores information of the sender, recipients for sending the email within a session
    • POP3 and IMAP: maintain a working session of users
  7. When does DNS use UDP / TCP?
    • UDP: the size of the response message is less than 512 bytes
    • TCP: the size of the response message is greater than 512 bytes
  8. Each Internet host will have at least one local name server and one authoritative name server (primary server + secondary server). What role does each of these servers have in DNS?
    • A host’s authoritative name server provides the “official” translation of a hostname to an IP address (among other things)
    • A host’s local name server is a proxy to the DNS system: the host first queries its local name server for mapping; the local name server then obtains the mapping on behalf of the querying host
  9. In a DHT-based network, what is the size of peer-identifier space? And what is the range of values in this space?
    • 2^m (each identifier is m-bit long)
    • 0 ~ $2^m-1$
  10. In Kademlia, assume m=4 and active nodes are N4, N7, and N12. Where is the key k3 stored in this system?
  • k3 is stored at node N7 (3⊕4= 7, 3⊕7= 4, 3⊕12=15)
  1. Consider the following string of ASCII characters that were captured by Wireshark when the browser sent an HTTP GET message (i.e., this is the actual content of an HTTP GET message). Answer the following questions, indicating where in the HTTP GET message below you find the answer.

joowan1108

  • What is the URL of the document requested by the browser?

    /cs453/index.html

  • What version of HTTP is the browser running?

    HTTP/1.1

  • Does the browser request a non-persistent or a persistent connection?

    Keep-Alive:300, Connection: keep-alive $\rightarrow$ Persistent connection

  • What is the IP address of the host on which the browser is running?

    No information about IP address. In client, when using GET method, it only contains information about url, method name, HTTP version.

  • What type of browser initiates this message? Why is the browser type needed in an HTTP request message?

    Netscape browser

    Browsers have different capabilities for example, being able to run active web pages and etc. Also, it can tell if the device used by the client is web or phone, and what OS its using.

  1. Email communication on the Internet relies on several protocols, including MIME, SMTP, IMAP4, POP3. These protocols work together in an email system, each serving a different role. For example, Ana writes an email on her laptop and clicks Send. The email client sends the message to the university mail server, which may forward it to another mail server on the Internet. Which protocol mainly handles sending the email in this process?

    A. MIME

    B. SMTP O

    C. IMAP4

    D. POP3

  2. Which of the following statements is TRUE about Client-Server and Peerto-Peer (P2P) networks

    A. Computer applications that use the client-server network include email, network printing, and the World Wide Web

    $\rightarrow$ T

    B. P2P application is file-sharing programs such as BitTorrent, TErminaL NETwork (TELNET) where users share files directly with each other without a central server

    $\rightarrow$ F

    C. Hybrid P2P networks combine elements of client-server and P2P architecture. A well-known example is Skype application

    $\rightarrow$ T

    D. All of them are TRUE

  3. Which of the following statements is TRUE?

    A. The socket interface is a set of instructions that provide communication between the application layer and operating system

    $\rightarrow$ T

    B. Socket is not a data structure that is created and used by the application system

    $\rightarrow$ F

    C. The server needs a local (client) and a remote (server) socket addresses for communication

    $\rightarrow$ F

    D. A key component of the socket address is the IP address and port number

    $\rightarrow$ T

  4. Client Server vs Peer to Peer

    Element roles: client, server vs peer

    Service: Provided by service vs All become providers

    Main purpose: Information share vs Information share

    Management: Centralized vs Decentralized

    Bottleneck: Single server vs distributed server

  5. When you open a website, the browser uses several parts of the URL to locate the exact page. For example, a student wants to visit http://monet.skku.ac.kr/main/. Which of the following pieces of information are used to identify this specific web page?

    A. Protocol: O http

    B. Host: O monet.skku.ac.kr

    C. Port O defined in client server app

    D. Path O /main

  6. To successfully access the initial landing page of our lab’s website http://monet.skku.ac.kr/main/, which range of HTTP status codes you would typically expect to receive?

    A. 100-199

    B. 200-299: O

    C. 300-399

    D. 400-499

    E. 500-599

  7. Imagine a Stateless Server and a Client are talking. Suddenly, the Server crashes, restarts, and loses everything in its short-term memory (RAM). Which statement is TRUE?

    A. The Server is harder to recover because it has to remember every single user’s ID. X

    B. The Client can just ask again. Since the Server never “remembered” the user anyway, restarting doesn’t break the conversation O

    C. The connection uses less data because the Client doesn’t have to reidentify itself X

  8. Which statements are True about Electronic mail?

    A. Electronic mail (or E-mail) allows users to exchange messages and is considered a one-way transaction O

    B. There are two types of UA (User Agent): command-driven UA and GUIbased UA O

    C. The process of transferring a mail message occurs in three phases: Connection establishment, Message Transfer, and Connection termination O

    D. SMTP, POP3 and IMAP are stateless protocols. They maintain and store the past information for further uses X

    They are stateful!!!!

  9. Which of the following operations in a standard clientserver exchange is considered idempotent? An operation is idempotent if performing it multiple times has the same effect as performing it once.

    A. Making a DNS request to look up the IP address of a domain name O

    B. Sending multiple HTTP POST requests to submit a form X

    C. Repeating the same HTTP DELETE request to remove a resource O

    D. Both A and C O

  10. Based on the figure, after the server’s listen socket receives a connection request, a new socket is created for that client. Which statement is TRUE about this newly created socket by accept()?

    A. It uses a different port number than the original listen socket X

    B. It is a “listen socket” that can accept further new connections X

    C. It represents a unique 5-tuple (Protocol, Local IP, Local Port, Remote IP, Remote Port) specific to that client O

    D. It must be closed before the server can receive another connection request X

    $\rightarrow$ Listen socket이 받는 것이고 accept()으로 생겨난 socket은 그냥 client와 data을 주고 받기 위한 socket이라서 another connection request 받을 수 있음

  11. Problem

    joowan1108

    joowan1108

  12. Non persistent and persistent connections in HTTP

    A. What is the main difference between them?

    Non-persistent connection: A separate TCP connection is established for every single request/response pair. Once the server sends the requested object, the TCP connection is immediately closed. If a webpage has 10 images, the browser must perform 10 separate three-way handshakes.

    Persistent connection: The server leaves the TCP connection open after sending a response. This allows the client to send multiple requests (and receive multiple responses) over the same connection, significantly reducing the overhead of repeatedly setting up and tearing down TCP sessions.

    B. What are the HTTP versions used?

    Non-persistent: This was the default behavior for HTTP/1.0.

    Persistent: This became the default starting with HTTP/1.1. It is also the foundation for HTTP/2 and HTTP/3 (though HTTP/3 uses QUIC over UDP, it maintains the persistent concept).

    C. Which one supports multiple streams over a single TCP connection?

    None of them. The ability to support multiple concurrent streams (multiplexing) over a single connection is a hallmark of HTTP/2.

    D. What kinds of connections do modern browsers use?

    Modern browsers like Chrome, Firefox, and Edge exclusively use persistent connections.

    Specifically, they prefer HTTP/2 or HTTP/3. If the server doesn’t support those, they fall back to HTTP/1.1. Browsers also often open multiple parallel persistent connections (usually up to 6) to a single domain to further speed up the loading process.

  13. Which statement(s) is/are TRUE about centralized and decentralized P2P networks?

    A. Both centralized and decentralized can use the Distributed Hash Table (DHT) for file lookup F

    B. In decentralized P2P networks, peers form an overlay network on top of the Internet. T

    C. In decentralized P2P systems, the directory or indexing information is distributed across multiple nodes. T

    D. Gnutella is centralized whereas Freenet is decentralized F

  14. Hashing is a mathematical process that maps data of any size to a fixed-length value, often called a “hash” or “fingerprint,” to identify or locate information efficiently. Which statement(s) is/are TRUE about hashing?

    A. Hashing is a mapping function T

    B. Both Chord and Kademlia require to use a hash function T

    C. Handling node arrival requires running a hash function in both Chord and Kademlia T

    D. Chord can deal with node departure while Kademlia cannot F

  15. Answering TRUE/FALSE in Chord:

    A. The closest node to the key 𝑘 will host the value 𝑘 F

    B. Each node in Chord stores information of 𝑚 other nodes F, m+1 nodes (the precessor node)

    C. Chord is typically a P2P lookup protocol T

    D. An identifier space of size $2^𝑚$ points is distributed in a circle in the counterclockwise direction F

  16. Answering TRUE/FALSE in Kademlia:

    A. Its routing table is also called finger table F

    B. Use XOR to calculate the distance between two nodes T

    C. Use NOR to calculate distance between keys F

    D. Assume N4, N7 and N11 are three active nodes, then key k8 is stored in N11 T

  17. In a Kademlia network, the identifier space is 256. Compute the following:

    A. What is the number of leaf nodes? $2^8$ so 8

    B. What is the number of rows, columns in each routing table? rows: 8, columns: k bucket size

    C. What is the number of subtrees that each node has? 256

    D. What is the height of the tree? 8

  18. You are downloading a large movie file using a BitTorrent client. While monitoring the download, you notice that your computer is receiving pieces of the file from several different peers at the same time. You also see terms like seed and leech in the interface. Based on this situation, which of the following statements are FALSE?

    A. A peer in BitTorrent downloads data from only one peer at a time. F

    B. A leech is a peer that has only part of the file and is still downloading the remaining pieces. T

    C. All peers in a BitTorrent network are called seeds. F

    D. BitTorrent always requires a central server (tracker) to function F

  19. In BitTorrent, a node uses the “Tit-for-Tat” strategy by stopping data uploads to peers who do not upload anything back. Which of the following is/are TRUE for this behavior?

    A. To prevent “Free-Riding” by ensuring users contribute to the network T

    B. To reduce the total number of connections to save RAM F

    C. To prioritize sending data to the newest users in the swarm F

    D. To encrypt the data so that only “Peer A” can read it F

  20. Which statements are True/False about Socket Programming in four different languages?

    A. In C, SOCK_STREAM is used for connectionless UDP communication, while SOCK_DGRAM is used for reliable, connection-oriented TCP communication. F

    B. C++ provides the std::thread class for thread management, allowing developers to create and control threads easily. T

    C. Python socket programming requires more complex syntax and external libraries, leading to larger and more convoluted code compared to Java, C, or C++. F

    D. In Java, the server side of a socket connection is handled by the ServerSocket class. To handle multiple clients simultaneously, threads (Thread) are required. T