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

P2P Netfwork with Node.js

P2P Netfwork with Node.js

P2P NetworkをNode.jsで入門してみた話

Hayato Koriyama

May 30, 2018
Tweet

More Decks by Hayato Koriyama

Other Decks in Programming

Transcript

  1. 11/FUXPSLJOHXJUI
    /PEFKT
    ೖ໳ͯ͠Έͨ

    View full-size slide


  2. w !OFLPCBUP
    w 'SPOUFOE&OHJOFFS
    w גࣜձࣾϞόΠϧϑΝΫτϦʔ

    View full-size slide

  3. ࠓ೔ͷ࿩
    w ͳΜ͔࠷৽ͷྲྀߦΛ௥͓͏ͱࢥ͚ͬͨͲ΍Ίͨ
    w /PEFKTͰ11ωοτϫʔΫೖ໳ͨ͠࿩
    w /PEFKTͰ11ωοτϫʔΫΛߏங͢Δ·Ͱͷ࿩

    View full-size slide

  4. ࠓ೔͠ͳ͍࿩
    w 8FC35$ͷ࿩
    w ϓϩτίϧͷӅṭ
    w 伴ަ׵ʹΑΔσʔλͷӅಗͱ͔

    View full-size slide

  5. -JTL
    w -JTLCMPDLDIBJOBQQMJDBUJPOQMBUGPSN
    w IUUQTMJTLJP
    w /PEFKTͰ࣮૷͞ΕͨϒϩοΫνΣʔϯΞ
    ϓϦέʔγϣϯ
    w ࠷ۙίʔυΛಡΜͩˍࢀߟʹ͠ͳ͕Βࣗ
    ෼Ͱॻ͍ͨͷͰωοτϫʔΫ෦෼ͷ஌ݟ

    View full-size slide

  6. 8FC35$Ͱ͸ͳ͍ͷ͔
    w 8FC35$͸TUVO UVSOαʔόʔΛ༻ҙ͢Δ౎߹ͰӡӦ͕τϥϑΟο
    ΫΛࢧ͑Δඞཁ͕͋Δ
    w ʢ1FFSʹͦͷ໾ׂΛ࣋ͨͤΔͱ͍͏ํ๏΋͋Γ·͢ʣ
    w TUVO*1ΞυϨεͷऔಘ
    w UVSOσʔλͷதܧ
    w EFDFOUSBMJ[FEͱ͸ݴ͑ͳ͍

    View full-size slide

  7. EFDFOUSBMJ[FEͳ11
    w μ΢ϯ͠ͳ͍ωοτϫʔΫͷඞཁੑͬͯ
    w ӡӦ͕ؤுΕ͹ྑ͍ͷͰ͸
    w ຊ౰ʹμ΢ϯͯ͠͸͍͚ͳ͍αʔϏεͳΜͰ͔͢ʁ

    View full-size slide

  8. EFDFOUSBMJ[FEͳ11
    w ˠެݖྗʹӡӦαʔόʔΛ཈͑ΒΕͯ΋ಈ͖ଓ͚Δ
    w ˠެݖྗʹରͯ͠ϩοΫϯϩʔϧ͍ͯͧ͘͠ɺͱ͍͏ҙࢤΛ΅͔
    ͨ͠΋ͷ

    View full-size slide

  9. 11ߏங·Ͱͷ̎ͭͷน

    View full-size slide

  10. /BUͷน
    w /BU5SBWFSTBM
    w ͍ΘΏΔ/BUӽ͑ɺϙʔτ։์ɺ1PSU.BQQJOHT
    w )PMF1VODIJOHͱ΋ݴ͏Β͍͠
    w ·ͣ5$1ϙʔτ͕ۭ͍ͯͳ͍
    w ˠ૬ख͔Βࣗ෼ͷ4PDLFUʹܨ͙͜ͱ͕ग़དྷͳ͍
    w ϧʔλ͕V1O1ʹରԠ͍ͯ͠Ε͹ϧʔλʹ1PSU.BQQJOH͢Δ͜ͱ͕Մೳ

    View full-size slide

  11. /BUͷน
    w ੲͷ11ιϑτ͸Ϣʔβʔ͕खಈͰ։์ͷઃఆ 1PSU.BQQJOH
    Λ
    ͢Δඞཁ͕͋ͬͨ
    w ࠷ۙͷՈఉ༻ϧʔλ͸େ఍ͷ৔߹V1O1ʹରԠ͍ͯ͠ΔͷͰɺࣗ
    ಈͰϙʔτ։์͢Δ഑ྀ͕Մೳ
    w اۀωοτϫʔΫ಺͔Β͸ϙʔτ։͚ͯ΋Β͍ͬͯͩ͘͞

    View full-size slide

  12. 1PSU.BQQJOHͷखॱ
    w ωοτϫʔΫ಺ͷϧʔλΞυϨεͱϚοϐϯάઃఆͷΤϯυϙ
    ΠϯτΛ୳͢ TTEQ

    w ϧʔλʹάϩʔόϧ*1ΞυϨεΛ໰͍߹ΘͤΔ TPBQ

    w ϧʔλʹϙʔτϚοϐϯάͷཁٻΛૹΔ TPBQ

    w Ұ࣌తʹϙʔτ͕։͘ʂ
    w ͋ͱͰดΊ·͠ΐ͏ TPBQ

    View full-size slide

  13. ϧʔλΛ୳͢

    View full-size slide

  14. ϧʔλʹ(MPCBM*1Λฉ͘

    View full-size slide

  15. ϧʔλʹ(MPCBM*1Λฉ͘

    View full-size slide

  16. w 44%1ͬͯԿ
    w ωοτϫʔΫ಺ͰV1O1ʹରԠͨ͠ػثΛ୳ࡧ͢ΔͨΊͷϓϩτί
    ϧ
    w 40"1ͬͯԿ
    w 3&45͕ྲྀߦΔલʹଘࡏͨ͠9.-ϕʔεͷ31$ϓϩτίϧ
    w ݹ͍ʂ
    w Ͱ΋V1O1ରԠϧʔλʹ͸͜Ε͕ೖͬͯΔ

    View full-size slide

  17. w ͜ͷखଓ͖Λ౿Ή͜ͱͰϧʔλͷ؅ཧը໘΁ͷݖݶ͕ແͯ͘΋ϙʔ
    τ։์͕Մೳ
    w OPEFOBUVQOQͱ͔ͰͰ͖Δ͔΋
    w ະݕূʢશ෦ॻ͍ͯ͠·ͬͨͷͰʣ

    View full-size slide

  18. 11ߏங·Ͱͷ̎ͭͷน

    View full-size slide

  19. ॳظಉظͷน
    w ֎෦ͷਓͱ΍ΓͱΓͰ͖ΔΑ͏ʹͳͬͨͷͰ୭͔ͱܨ͕Γ͍ͨ
    w 1FFS-JTU͕ͳ͍

    View full-size slide

  20. ॳظಉظͷน
    w ωοτϫʔΫʹࢀՃ͢ΔͨΊͷ৘ใ
    w ॳظϊʔυ
    w ωοτϫʔΫ্ʹԿ͕͋Δͷ͔
    w ϑΝΠϧ΍#MPDL৘ใ

    View full-size slide

  21. ॳظಉظͷน
    w ॳظϊʔυΛͲ͏΍ͬͯಘΔͷ͔
    w 8JOOZ΍4IBSF͸༗ࢤϙʔλϧαΠτͳͲͰ૲ͷࠜڞ༗
    w &UIFSFVNͳͲϒϩοΫνΣʔϯܥ͸։ൃݩ͕༻ҙͨ͠ઈରܨ͕Δϊʔυ͕ଘࡏ
    ͢Δ͜ͱ͕ଟ͍
    w 3PDLO3PMMͳ৔߹͸Ͳ͔͔͜ΒॳظϊʔυΛ࢓ೖΕΔඞཁ͋Γ
    w ։ൃݩϊʔυ͕શͯΛ༩͑Δͷ͸ෛ୲͕ภΔͷͰɺ։ൃݩϊʔυ͔Βऔಘ͢Δͷ͸
    ϊʔυ৘ใͷΈɺଞͷσʔλ͸ωοτϫʔΫ্ͷ(PPE1FFS͔Β΋Β͏ͳͲͷ޻෉
    ͕ඞཁ

    View full-size slide

  22. (PPE1FFS#BE1FFS
    w 1FFS͕ಛఆͷ୭͔ʹσʔλΛ໰͍߹Θ͍ͤͨ৔߹ɺର৅ͷ1FFSΛબఆ͢Δͷʹ(PPE1FFS͔Ͳ͏͔൑அ͢Δ
    ࢦඪ
    w ໰͍߹Θͤઌ͕গͳ͍৘ใ͔͍࣋ͬͯ͠ͳ͔ͬͨΒແବ଍ωοτϫʔΫΛ݈શʹอͯͳ͍
    w શવܨ͕Βͳ͍1FFS৘ใΛ౉͞Εͯ΋ɺॱ൪ʹ֬ೝ͢Δ͜ͱ͔͠Ͱ͖ͳ͍
    w ࢦඪ
    w σʔλΛΑΓଟ͍࣋ͬͯ͘Δ
    w σʔλ͕࠷৽Ͱ͋Δ
    w WFSTJPO͕࠷৽Ͱ͋Δ
    w IBOETIBLF΍ઐ༻ͷνϟϯωϧͰ΍ΓͱΓ͢Δ

    View full-size slide

  23. (PPE1FFS#BE1FFS
    w 8JOOZ
    w ωοτϫʔΫͷ଎౓ʢࣗݾਃࠂʣ
    w ଎౓Λ্ྲྀͱԼྲྀʹ෼͚Δ͜ͱͰɺωοτϫʔΫͷετϨεΛݮ
    Βͦ͏ͱͨ͠
    w ্ྲྀϊʔυʹσʔλ͕ू·Δ࢓૊Έྲྀ଎͕଎͍

    View full-size slide

  24. (PPE1FFS#BE1FFS
    w 1FSGFDU%BSL
    w ॴ༗͢ΔετϨʔδͷྔ
    w ετϨʔδ͕ଟ͍ωοτϫʔΫʹߩݙ͍ͯ͠Δ

    View full-size slide

  25. (PPE1FFS#BE1FFS
    w &UIFSFVN HFUI

    w IFJHIUʢ͍࣋ͬͯΔϒϩοΫ਺ʣͷ஋
    w IFJHIU͕ߴ͍࠷৽Ͱ͋ΔՄೳੑ͕ߴ͍

    View full-size slide

  26. (PPE1FFS#BE1FFS
    w #JU$PJO
    w $ಡΉͷ͕͠ΜͲ͔ͬͨ

    View full-size slide

  27. (PPE1FFS#BE1FFS
    w -JTL
    w ݱࡏίωΫγϣϯϦετͷઌ಄Λ͖࣋ͬͯͯΔ͚ͩ

    View full-size slide

  28. (PPE1FFS#BE1FFS

    View full-size slide

  29. ࣗ෼Ͱ͸Ͳ͏͔ͨ͠
    w GPS&BDIͨ͠
    w ૬खͷෛՙΛΨϯແࢹ

    View full-size slide

  30. ͜͜·ͰདྷͯΑ͏΍͘
    11ωοτϫʔΫ͕ߏங͞ΕΔ

    View full-size slide

  31. ͜ͷޙͷωοτϫʔΫʹ࢖͏
    ϓϩτίϧ
    w WT
    w )551 -JTL /&0

    w KTPO31$ &UIFSFVN

    w H31$ &UIFSFVN

    w ϦϨʔ
    w 8FC4PDLFU -JTL /&0 &UIFSFVN

    w ;FSP.2

    View full-size slide

  32. ͍ͭͰɿωοτϫʔΫͷҡ࣋ํ๏

    View full-size slide

  33. ײ૝
    w 11ωοτϫʔΫͷ͜ͱΛௐ΂ΔʹͭΕͯ8JOOZ΍4IBSFͬͯΑ͘
    ग़དྷͯΔͳ͊ͱ͍͏ײ૝
    w ͚Ͳྺ࢙తܦҢʹΑ໊ͬͯલΛग़͠ʹ͍͘
    w දʹग़͠ʹ͍͘ʂʂʂ
    w ׬શ෼ݖΛᨳ͏ϒϩοΫνΣʔϯ͸11ωοτϫʔΫͱෆՄ෼
    w දʹग़͠΍͍͢ʂʂʂ

    View full-size slide

  34. ײ૝
    w #JU$PJO͔Β࢝·ΔϒϩοΫνΣʔϯ܈ʹΑͬͯ11ωοτϫʔΫͷ
    धཁ͕ߴ·͖ͬͯͨ
    w ωοτʹམͪͯΔ೔ຊޠ৘ใ͕ݹ͍
    w ͍͍ͩͨࣗ෼Ͱॻ͔ͳ͖Ό͍͚ͳ͍ਏ͕͋͞Δ
    w φ΢ͳٕज़ք۾ͷਓɺ11ωοτϫʔΫॻ͍ͯ΄͍͠

    View full-size slide

  35. MJCQQͱ͍͏ͷ͕͋ΔΒ͍͠
    11ʹඞཁͳॾʑΛ৭ʑͳݴޠͰ࣮૷ͨ͠Ϟδϡʔϧ܈
    ͕ɺ/PEFKTϞδϡʔϧ͸͋·Γἧͬͯͳ͍

    View full-size slide