lesson-04.html 10 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Computer Networks (4)</title>
<meta name="cours-n" content="4">

<meta name="author" content="Rémi Emonet">
<meta name="venue" content="DWA M1 WI/MLDM">
<meta name="date" content="2017">
<meta name="affiliation" content="Université Jean Monnet − Laboratoire Hubert Curien">
<style type="text/css">
.inlineimages img {display: inline !important; }
.slide .above {position:absolute; left: 20px; top: 20px; width: 760px; height: 460px; text-align:center;}
.above {z-index: 100 !important;}
tt {border: 1px solid #DDD;}
</style>

<!--
<script src="deck.js/extensions/includedeck/load.js"></script>
<script src="extensions/slides-dev.js"></script>
-->
<script src="extensions/deck-packed.js"></script>
<script src="extensions/slides.js"></script>
<script>go()</script>
</head>

<body>

<div class="deck-container">

<div class="deck-loading-splash" style="background: black; color: chartreuse;"><span class="vcenter" style="font-size: 30px; font-family: Arial; ">Please wait, while our marmots are preparing the hot chocolate…</span></div>

<section class="smart">

# @chunk: chunks/title.md

# @chunk: chunks/objectives.md

# Reminder {no-print}

## Projects {no-print}
- Subject
- peer to peer file sharing, kind of bittorent
- Phase 1 : group creation
- group and team creation, sending an email
- name and github username (of each member)
- chosen programming language for the project
- deadline: **Tuesday, January 17th, 22h** // then I invite
- Phase 2
- understanding of the subject
- creation of a protocol specification (version 1)
- Phase 3 {libyli}
- implementation
- test
- documentation of possible evolutions


<!-- plan -->
## Part 2: Application Layer{#plan overview}
@SVG: media/stack-index.svg 100px 400px {svg floatright app margin-left-minus-100}

- Goal{shaded}
- protocols: general principles and existing protocols
- sockets: programming and services from the transport layer
- Overview
- Principles of distributed applications {it1}
// and interactions with the transport layer
- HTTP and the web {it2}
- FTP: file transfer {it3}
- Electronic mail {it4}
- DNS: name resolution and more {it5}
- P2P Applications (peer to peer) {it6}
- Network programming: using sockets {it7}
# @copy:#plan




<!-- P2P -->
# @copy:#plan: %+class:inred: .it6

# Peer-to-Peer (P2P) and the BitTorrent Example // who used torrents? {no-print}

## P2P Architectures
@SVG: media/part2/internet-client-server-p2p.svg 300px 400px {svg floatright}

- Pure P2P{pur}
- No server (that need to be always on)
- Any host
- peer to peer communications
- connection, disconnection // to the network
- changing IP
- In practice{pratique}
- sometimes, some support/organization servers
- or some peers that are more important
- @anim: -#arrowsclientserver + -#mask-border2 + .pur | .svg | .pratique


## How long does it take to distribute the file to all clients using a client/server architecture?{question bottom}
@SVG: media/part2/p2p-clientserver-capacities.svg 700px 150px {svg centered}

## How long does it take to distribute the file to all clients using a peer-to-peer architecture?{question bottom}
@SVG: media/part2/p2p-clientserver-capacities.svg 700px 150px {svg centered}

## BitTorrent: Principles and Architecture
- File (or group of files) split in chunks of 256kb (16kB)
- Torrent{slide}
- a group of machines (processes)
- exchanging the chunks of a file
- Tracker{slide}
- server maintaining a list of the torrent participants
- useful for new peers
- relatively low processing charge, easily replaceable
- What a new peer does{slide}
- asks the tracker for a (sub)list of peers
- connects to each peer asking chunks
- receives chunks
- then, can simultaneously send/receive chunks{slide}
- reconsiders connections{slide}
// peer left, new ones, ...
- when all chunks are obtained &rarr; leave or stay?{slide}

## BitTorrent: Distributed Optimization // ants, multi-agent?

- Selecting the chunk to download{slide}
- periodically obtain a list of chunks from the neighbors
// neighbor = connected peers
- query missing chunks, starting with the most rare
// rare, in the neighborhood
- Choosing which peer to send chunks {slide}
- send to the 4 peers that upload the fastest (to me)
// best bandwidth
- ignore other requests
- re-evaluate every 10 seconds
- selecting a peer randomly
- every 30 seconds
- sending to a new peer
- goal: test the speed of new peers
- if not enough peers
- ask the tracker again
- Global result {slide}
- replication of the rarest chunks
- optimized communication with high-throughput peers
// close, fast, etc, no waste





<!-- prog sockets -->
# @copy:#plan: %+class:inred: .it7

# Programming: TCP and UDP sockets in Java {no-print}

## Socket Programming
@SVG: media/part2/socket.svg 700px 200px {svg centered}

- socket
- interface to the “transport” layer
- interface to a remote process
- abstraction of everything else
- Objective {slide}
- programming distributed applications
- with a minimal amount of knowledge on the network
- 2 types of sockets: UDP, TCP{slide}
// UDP, no guarantees, sending datagram/packets
// TCP, guaranteed transport, connection oriented, data stream


## UDP Programming
- No connection between clients and servers
- no initialization
- directly sending packets (to IP:port)
- address of the sender (IP:port) in the paquet
// for the potential answer
- Unreliable transport {slide}
- possibility of loss
- possibility of re-ordering
- For the applications{slide}
- need to know the IP:port of the destination
- ex: a known server with a know port
- Java `DatagramPacket` class {slide}
- UDP “packet” (segment)
- Java `DatagramSocket` class {slide}
- interface to exchange packets
- bi-directional: send/receive


# UDP Programming in Java <br/> live (echo) {no-print}


## TCP Programming
- Reliable bi-directional connection between two processes
- connection IP:port ⇄ IP:port
- connection seen as a two streams
- Connection establishment {slide}
- a “server socket” listens for new connection (a port)
- a client contacts this server (from a local port)
- a new socket is created on both sides // socket object, no new port
- For the applications {slide}
- the server can wait for connections
- the client need to know the server's IP:port
- connection = two stream objects (each direction)
- Java `Socket` class {slide}
- a TCP communication to a remote process
- bi-directional: send/receive
- getOutputStream / getInputStream
- Java `ServerSocket` class {slide}
- to accept TCP connections from clients
- _factory_ (design pattern) of `Socket`


# Simple TCP Programming in Java <br/> live (echo, chat) {no-print}

## _Threads_ (and Java)
- Multiple execution threads in a program
- Code is (virtually or really) executed in “parallel”
- Problems of concurrent accesses
- shared variables (memory)
- modification of a container while iterating over it
- Solutions
- use only one thread
- use mutexes
- used _synchronized_ methods
- synchronization using robust concurrent-access message queues (`BlockingQueue`)


## Handling Concurrent Streams (network…) {libyli}
- Solution 1 (not recommended)
- one "accepting" thread
- one thread per client
- synchronization via `synchronized` or ad'hoc things
- Solution 2
- one "accepting" thread
- one thread per client
- one (or a few main) thread(s) for the logic
- communication between thread via message queues
- Solution 3
- using `select` (or `Selector`)
- single thread approach

# Java Programming and _Threads_ <br/> live {no-print}



## Key Points {#kp key deck-status-fake-end}
- {note-area}



</section>


<p class="deck-status" data-progress-size=": spe.top(10, 585) ; bottom: slide.top" style="z-index: 0; color: #339; background: #EEE;"> <span class="deck-status-current"></span> / <span class="deck-status-total"></span><span class="var-author">will be replaced by the author</span><span class="var-title">will be replaced by the title</span></p>

<a data-progress-size=": spe.top(15, 555); height: 45*designRatio; left: slide.right - 70*designRatio; width: 70*designRatio" class="ccby" href="http://en.wikipedia.org/wiki/Creative_Commons_license" title="This work is under CC-BY licence." target="_blank"></a>

<a class="ujm" data-progress-size=": spe.top(15, 525); height: 65*designRatio; left: slide.left; width: 130*designRatio" target="_blank"></a> <!-- shown only if with-ujm is set on the container -->

</div>
<!-- clicky Cla -->
<script type="text/javascript">
var clicky_site_ids = clicky_site_ids || [];
clicky_site_ids.push(100779706);
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//static.getclicky.com/js';
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
})();
</script>
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/100779706ns.gif" /></p></noscript>


<!-- Histats.com START (aync)-->
<script type="text/javascript">var _Hasync= _Hasync|| [];
_Hasync.push(['Histats.start', '1,2767123,4,0,0,0,00010000']);
_Hasync.push(['Histats.fasi', '1']);
_Hasync.push(['Histats.track_hits', '']);
(function() {
var hs = document.createElement('script'); hs.type = 'text/javascript'; hs.async = true;
hs.src = ('http://s10.histats.com/js15_as.js');
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs);
})();</script>
<noscript><a href="http://www.histats.com" target="_blank"><img src="http://sstatic1.histats.com/0.gif?2767123&101" alt="javascript hit counter" border="0"></a></noscript>
<!-- Histats.com END -->
</body>
</html>