Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ZeroServices
Search
Boris Feld
October 27, 2013
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ZeroServices
Présentation de ZeroServices, une libraire pour faire des services réseaux en P2P.
Boris Feld
October 27, 2013
More Decks by Boris Feld
See All by Boris Feld
BALTO, ONE TEST OUTPUT FORMAT TO UNITE THEM ALL
lothiraldan
0
75
Une révolution dans le monde des tests
lothiraldan
0
320
Mercurial changeset Evolution
lothiraldan
0
220
Python Unicode and Bytes Demystified
lothiraldan
0
300
Django 101
lothiraldan
0
280
Saltpad: A saltstack Web GUI
lothiraldan
5
28k
Mock considered harmful
lothiraldan
1
760
from Sync to Async Python, a AsyncIO migration
lothiraldan
2
780
Microservices késako
lothiraldan
0
170
Other Decks in Programming
See All in Programming
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
9
4.8k
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
270
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
410
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
仕様駆動開発の消費期限
watany
6
1.2k
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
230
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
120
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
550
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.8k
今さら聞けない .NET CLI
htkym
0
180
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
130
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The agentic SEO stack - context over prompts
schlessera
0
860
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Making the Leap to Tech Lead
cromwellryan
135
10k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
400
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Designing for Timeless Needs
cassininazir
1
430
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Agile that works and the tools we love
rasmusluckow
331
22k
Transcript
ZeroServices FELD Boris - PyconFR 2013
[email protected]
/me • FELD Boris - DevTools • Tornado FTW •
@lothiraldan un peu partout sur le web • https://github.com/Lothiraldan/ ZeroServices
ZeroService • Librairie pour écrire des Services P2P • Python2.x
• Very Alpha
ZeroServices Pourquoi ?
Besoins • AutoDiscovery • Multicast / Unicast • Découverte des
pertes de pairs
Network is difficult
Peer To Peer is difficult
Choix technologiques
Pourquoi ØMQ ? • Sockets BSD trop bas niveau. •
RabbitMQ... NOPE. • ØMQ FTW. • L’ioloop est packagée dans PyZMQ.
AutoDiscovery UDP Multicast
Communication Unicast / Multicast ZeroMQ
Découverte des pertes Heartbeating (to do)
None
Retour d’expérience
L’asynchrone c’est difficile
Tester de l’asynchrone c’est douloureux
Quelques trucs • Isoler au maximum la partie asynchrone •
La tester avec des mocks • Mocker la partie asynchrone
Exemple class ZeroMQMediumTestCase(unittest.TestCase): def setUp(self): self.service = ServiceMock() self.ioloop =
IOLoop.instance() self.medium = ZeroMQMedium(self.service, ioloop=self.ioloop) def testRegister(self): self.medium.register() self.ioloop.start() self.assertEqual(self.service.on_registration_message.call_count, 1)
Exemple II class BaseServiceTestCase(unittest.TestCase): def setUp(self): self.medium = TestMedium() self.service
= BaseService(self.medium) def testOnRegistration(self): node_info = {'name': 'Service 1'} self.service.on_registration_message(node_info) self.assertEqual(self.medium.send_registration_answer.call_count, 1)
Les topologies réseaux est hétérogène
Vous allez toujours avoir des topologies de réseau tordues
Au choix • Firewall • NAT • VPN • DMZ
• Pas d’UDP Multicast
None
Traitez les quand ils arrivent
Pas de solutions magiques en P2P
Des techniques • Utiliser le port 443 ou 80 •
UDP Hole Punching • Encapsuler le traffic dans HTTP
Une solution ? • Avoir un pair central • Qui
forward le traffic
ZeroService is not perfect • Pas d’ack pour les messages
• Pas d’heartbeat • Une socket par message sortant • UDP Multicast / ZeroConf • Marche en LAN. Pas en WAN.
Exemple
Le service de chat class ChatService(BaseService): def __init__(self, username): self.username
= username super(ChatService, self).__init__(ZeroMQMedium(self, port_random=True)) def service_info(self): return {'name': self.username}
Le service de chat class ChatService(BaseService): def on_event(self, message_type, message):
"""Called when a multicast message is received """ msg = {'type': message_type} msg.update(message) self.send_to_all_clients(json.dumps(msg)) def on_message(self, message_type, **kwargs): """Called when an unicast message is received """ msg = {'type': message_type} msg.update(kwargs) self.send_to_all_clients(json.dumps(msg)) def on_new_node(self, node_info): """Called when a new peer joins """ msg = json.dumps({'type': 'user_join', 'id': node_info['node_id'], 'name': node_info['name']}) self.send_to_all_clients(msg) def on_node_close(self, node_info): """Called when a peer leaves """ msg = json.dumps({'type': 'user_leave', 'id': node_info['node_id'], 'name': node_info['name']}) self.send_to_all_clients(msg)
La partie Tornado class MainHandler(web.RequestHandler): def get(self): return self.render('chat.html', port=int(sys.argv[2]),
name=sys.argv[1])
La partie Tornado clients = [] class WebSocketHandler(websocket.WebSocketHandler): def open(self):
clients.append(self) for node_id, node in s.nodes_directory.items(): msg = json.dumps({'type': 'user_join', 'id': node_id, 'name': node['name']}) self.write_message(msg) def on_close(self): clients.remove(self) def on_message(self, message): message = json.loads(message) if message['type'] == 'message': msg = {'username': sys.argv[1], 'message': message['data']['message']} s.publish(str(message['type']), msg) elif message['type'] == 'direct_message': msg = {'from': sys.argv[1], 'message': message['data']['message']} s.send(message['data']['to'], msg, msg_type=str(message['type']))
Chat.py urls = [ (r"/", MainHandler), (r"/websocket", WebSocketHandler), (r"/static/(.*)", web.StaticFileHandler,
{"path": "."})] if __name__ == '__main__': application = web.Application(urls, debug=True) application.listen(int(sys.argv[2])) try: ioloop.IOLoop.instance().add_timeout(time() + 1, s.medium.register) ioloop.IOLoop.instance().start() except KeyboardInterrupt: s.close() for client in clients: client.close()
La demo chat • 69 lignes de python • Pas
de serveur central • API qui se veut simple
DEMO !
Questions ?