Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goだけでロビーサーバーを作ってみた

irieda
October 05, 2018

 Goだけでロビーサーバーを作ってみた

GoとGopherJSによるIsomorphicな実装で
P2Pメッシュを確立できるロビーサーバーを作ってみた話。

irieda

October 05, 2018
Tweet

More Decks by irieda

Other Decks in Programming

Transcript

  1. Go ͚ͩͰ
    ʓʓʓʓΛ࡞ͬͯΈͨ

    View full-size slide

  2. ͓લ୭Αʁ
    ًؕزٗاؿز㾊
    1ZUIPOJTUB(PQIFS
    ז׿ד׮(Pד剅ְ׍ׯֲמה
    (P娖כ䎃穗麓ֻ׵ְ
    ؟؎ز
    ⠓爡-BC ַ׵倜爡せ

    )/!OPCPOPCP
    IUUQHPMBOHSEZKQ

    View full-size slide

  3. ࡢࠓͷ AltJS ࣄ৘

    View full-size slide

  4. ߴڃݴޠͷ AltJS
    㢌䳔דֹזְ
    넝秷鎉铂ך项欵ָ⢪ִזְ
    剅ֹ䩛ךأزٖأوحع
    ֿה׀הֻطةד穄✪

    View full-size slide

  5. JS ϔϏʔϢʔβʔஊ
    &4ח㢌䳔כת׌䗳銲
    ׃ַ׃ծ&4ך统׻׃כ䘌׸׹
    OPK2VFSZ VTF1SPNJTF
    &4.ד剅ְג♧אךؿ؋؎ٕחػحָؙ植㹋鍑
    "MU+4ז׵5ZQF4DSJQUָ剣劄

    View full-size slide

  6. JS ͷπϥϛ
    ٌآُ٦ٕ堣圓ךⴓ倖
    ꬊず劍ך剅ֹ倯ך㢌ꬠ劍
    &4غ٦آّٝⴓ倖
    㘗ָזְ㘗㼪Ⰵ䩛媮ח״׷ⴓ倖
    ؒ؝ءأذيךⴓ倖
    〢ְ٥倜׃ְ鎸鶢ה➰ֹさְ竲ֽ׷
    ײ׷ְؒٓ٦عٝسؚٔٝ

    View full-size slide

  7. TypeScript ͳΒʁ
    剑倜ך+4鎸鶢㘗ءأذيד剅ֽ׷
    ꫼涸㘗鎉铂ך䛷䜋ָ䖤׵׸׷
    䧭卓暟ךٌآُ٦ٕװ&4غ٦آّٝ׮鏣㹀ד鼅ץ׷
    +4ך项欵׮54ך项欵׮⢪ִ׷
    ا٦أوحفד54ا٦أדرغحؚ

    View full-size slide

  8. ͦ͜Ͱ GopherJS
    (Pך鎸鶢׾㢌䳔דֹ׷
    (Pךٌآُ٦ٕ堣圓׾ⵃ欽
    ؿ؋؎ٕחػحؙ⳿⸂
    KT HP (PQIFS+4ך项欵ָׅץג⢪ִ׷
    ꫼涸㘗鎉铂ך䛷䜋ָ䖤׵׸׷
    ا٦أوحفד(Pا٦أדرغحؚ
    ꬊず劍ך剅ֹ倯כ(Pؐؑ؎ָ然甧幥׫
    (Pך鎸鶢כ։䎃⽃⡘ד㸜㹀׃ג׷
    䓼㔿זؒٓ٦عٝسؚٔٝ俑⻉
    5ZQF4DSJQU״׶剣劄

    View full-size slide

  9. GopherJS+Vecty
    (Pה(Pךワ鴟خ٦ٕ׌ֽד
    ؿٗٝزؒٝسָ圓眠〳腉
    ׋׌׃$44כⴽ

    1BTTXPSE9דך䱰欽✲⢽،ٔ
    CPPUTUSBQ؝ٝه٦طٝزאֻ׏׋׃
    )5.-ַ׵7FDUZ欽鎸鶢׾欰䧭خ٦ٕ׮אֻ׏׋׃
    XBTN㼎䘔׮鹌遤⚥
    馄剣劄׌ה䙼׏ג׷

    View full-size slide

  10. ͜Ε·Ͱͷొஃωλ

    View full-size slide

  11. Go ϞόΠϧͰϐΞϊ App

    View full-size slide

  12. GopherJS ͷ঺հ
    .go
    .js
    .map
    GopherJS

    View full-size slide

  13. WebRTC Ͱ P2P
    Cloud
    NAT NAT
    Laptop
    Workstation
    Smart Phone
    Tablet
    Wireless Access Point

    View full-size slide

  14. Ծ૝ϥδίϯΧʔ

    View full-size slide

  15. Go Ͱ GUI Λͭ͘Δ
    "bridge":QObject

    View full-size slide

  16. Go ͚ͩͰ࡞ΔϑϩϯτΤϯυ

    View full-size slide

  17. ͜ΕΒͷొஃࢿྉ͸ʁ
    (PQIFS+4ד⡲׵׸גֶ׶תׅ٦

    View full-size slide

  18. ूେ੒ͱͯ͠ɾɾɾ

    View full-size slide

  19. Go ͚ͩͰ TPS Λ࡞Γ·ͨ͠

    View full-size slide

  20. ͱݴ͍͔ͨͬͨΜͰ͢
    ͕ɾɾɾ

    View full-size slide

  21. Go ͚ͩͰϩϏʔαʔόʔΛ࡞
    Γ·ͨ͠
    חז׏׍ׯְת׃׋٥٥٥ s٥ω٥

    View full-size slide

  22. ࡞Δͷʹඞࢮ͗ͯ͢ࢿྉ͕͠ΐ΅͍ͷ͸͝༰͍ࣻͩ͘͞ɾɾɾ

    View full-size slide

  23. ߏ੒
    ٗؽ٦؟٦غ٦
    11ًحءُطحزٙ٦ؙ
    8FC6*ؿٗٝزؒٝس
    %ٖٝتؚٔٝ

    View full-size slide

  24. ϩϏʔαʔόʔ
    8FC35$欽ءؚشؚٔٝ׾Ⱟי׷
    8FCTPDLFUTك٦أ
    ず儗剑㣐,䱸竲ծ,ٕ٦ي׾䟝㹀
    وحثؚٝ䖓11פ獳遤׃גٕ٦يכ嶊徦ׅ׷
    չ䖉׍فٖ؎պז׵,ِ٦ؠ٦ָׁלֽ׷
    فٖ؎➂〡׾㟓װׅ׌ֽז׵醱侧؟٦غ٦דأ؛٦ٕ
    植朐؟٦غ٦׾ת׋ְ׌وحثָؚٝדֹזְָծ
    㢩鿇16#46#ָ֮׸לדֹ׷״ֲחז׷

    View full-size slide

  25. P2P ϝογϡωοτϫʔΫ
    ؾ،כ(PQIFS+4ד圓眠
    8FC35$ך35$%BUB$IBOOFMⵃ欽
    ؾ،꟦׾湱✼ח䱸竲ׅ׷
    ِ٦ؠ٦ז׵ぐ䱸竲–ד䱸竲
    鸐⥋כ11ך׋׭⡚鹼䒀
    鹼䒀㼎瘻׾갹䓸׵זְד׮׉ֿ׉ֿ0,

    View full-size slide

  26. WebRTC ͱ DataChannel
    ֿתֳֽֿ׋ؚؚ֭׏ג
    ֿך僰װ׏הJ044BGBSJד׮0,חז׏׋
    ע׏׍ׯֽإحءّٝ然甧馄׭׿וְ
    1FFSה1FFS׾QVCTVC؟٦غ٦⢪׏גאזּךח
    ⚺㼪埄ָ❛✼ח䊡׷״ֲח➬鴥׬ךָ׭׿וְ

    View full-size slide

  27. ͦ͜Ͱٯసͷൃ૝
    ઀ଓͷ͖͔͚ͬ͸ Peer ͔Β Server ͚ͩͲɺ
    ੍ޚ͸ Server ͔Β Peer ʹ͢Δɻ
    ओैٯసͷൃ૝

    View full-size slide

  28. Peer-Server-Room

    View full-size slide

  29. ͦ͏͢Δͱ
    1FFSכ31$؟٦غ٦׾؟٦ـ
    1FFSכ31$؟٦غ٦׾؟٦ـ
    4FSWFSכ1FFSדDSFBUF0FS׾㹋遤
    4FSWFSכ1FFSדDSFBUF"OTXFS׾㹋遤
    4FSWFSכ1FFSח"OTXFS׾床ׅ
    31$ה⚺䖞鷞鯄ד⚺㼪埄׾床ֿׅהזֻ
    ء٦؛ٝءٍٕח11إحءّٝ׾然甧דֹ׷

    View full-size slide

  30. ݁Ռ
    ٗؽ٦הًحءُ然甧תד遤玎䏝
    *TPNPQIJD׌ַ׵ֿ׉SQDָ׉ךתת籬ָ׷
    ぐ1FFS꟦׾ًحءُדאזּך׮
    4FSWFS⩎דٕ٦ف׾穈׬׌ֽד0,
    姻䌢ח然甧דֹ׋׵֮הכ11ד
    4FSWFSכ8FC4PDLFUT׾ⴖ倖ׅ׷

    View full-size slide

  31. Web-UI ϑϩϯτΤϯυ
    (PQIFS+4欽ؿٗٝزؒٝسٓ؎ـٓٔ
    SFBDUٓ؎ؙ
    (P鎸鶢ד)5.-+4أة؎ٕ׾邌植
    XBTN㼎䘔׮㨣ת׏ג׷

    View full-size slide

  32. 3D ϨϯμϦϯά
    three.js
    (PQIFS+4כKT项欵ָ⢪ִ׷ָծ
    床ׅץֹ⦼ח♶⪒ָ֮׏ג׮
    搀鋔׃ג劍䖉鸐׶חז׵זְ
    הְֲ⹛涸鎉铂ך㹀׭׾׮䒷ֹ鴥׿ד׃תֲ
    ຊ౰͸͜͜΋ Go ʹ͍ͨ͠

    View full-size slide

  33. ⹛ֻ״ֲחז׏ג׷ַוֲַ׻ַ׵זְָ
    ಈ࡞σϞ
    https://gophertank.irieda.com

    View full-size slide

  34. ڝ߹ͷϚονϯάʢϩϏʔʣ
    αʔόʔ
    (P㹋鄲ח״׷ٗؽ٦؟٦غ٦ך畸さ
    ֿ׸׵חכ11؝طؙءّٝ堣腉כזְ
    ِ٦ؠ٦侧ח嫰⢽׃ג؟٦غ٦ٔا٦أ׾ؖٝؖٝ⢪׏׍ׯֲ
    (PPHMFכ㉀㡰涸ח׉׸ָ姻׃ְ​
    ֿ׸׵׮⡚ٖ؎ذٝء׾ֲ׋׏גכְ׷ֽו11ָ剑䓼׌״יկ
    IUUQTHJUIVCDPNIFSPJDMBCTOBLBNB
    IUUQTHJUIVCDPN(PPHMF$MPVE1MBUGPSNPQFONBUDI

    View full-size slide

  35. ·ͱΊ
    GopherJS ௒༗๬
    Vecty ௒༗ೳ
    Isomorphic ͸͍͍ͧ
    wasm ΁ͷນ։͚͸͙ͦͩ͢͜
    RTC ηογϣϯʹ͸ RPC ͱओैٯస͕༗ޮ
    Go ʹ WebGL αϙʔτϥΠϒϥϦ͕ཉ͍͠
    P2P ͸௿஗Ԇੑೳ͕࠷ڧ

    View full-size slide

  36. (PQIFS+4ך㈓♧ך䓲挿כⰕ䒭ׄׯזַ׏׋הֿ׹
    XBTN㼎䘔晛ָⰕ䒭ח《׶鴥ת׸׋
    זךד➙䖓כ㣐䩛׾䮶׏ג⢪ִ׷
    XBTN׮XFCSUD׮׮כװׅץגךًآٍ٦橆㞮ד⹛ֻ

    View full-size slide