►
From YouTube: Libp2p, a Rust peer-to-peer library. Pierre Krieger
Description
Pierre is a Rust programmer at Parity. He previously worked on graphics programming, including several Rust crates for Vulkan and OpenGL. He is now working on peer-to-peer networking.
The Rust libp2p library is the Rust implementation of the libp2p protocol initially created by Protocol Labs. Based on futures and tokio, it allows one to easily create a decentralized peer-to-peer network. This talk will introduce you to the main concepts of a peer-to-peer network, and how to use libp2p.
A
Good
morning,
everyone,
my
name-
is
Pierre
tiger,
also
known
as
Tanaka,
on
github
and
on
Twitter,
and
this
is
not
my
laptop
I'm,
sick,
I
hope
I'm
not
going
to
lose
my
voice.
So
everything
is
cool.
If
you
check
my
github
I
have
a
bunch
of
game.
Dev
related
driver,
isms,
the
graphics,
programming
related
libraries,
but
I'm
not
going
to
talk
about
game,
dev
of
graphic
or
graphics
programming
at
all.
A
So
I
am
going
to
assume
that
most
of
you
know
what
a
peer-to-peer
network
is
already
instead
of
having
a
central
server,
where
everyone
connects
to
all
the
clients
of
a
network,
the
article
a
connect
to
each
other,
which
is
better
for
a
lot
of
stuff
for
a
lot
of
reasons,
I'm
not
going
to
elaborate
before
no
BitTorrent,
Bitcoin
ipfs,
maybe
I
to
P,
maybe
I'm,
not
sure
check
them
out
on
Google,
and
so
how
does
a
peer-to-peer
network
work?
It's
made
of
four
components?
A
First,
each
node
inch
machine
vac
connects
to
the
network
is
identified
by
its
public
key,
its
cryptographic,
public
key
and
I'm,
going
to
elaborate
afterwards.
Second
component,
you
need
some
system
to
discover
how
to
connect
to
the
network.
Third
component,
you
need
a
messaging
system,
a
publish/subscribe
system,
no
two
proper
way
to
propagate
events
on
the
network
and
fourth
component,
a
distributed
hash
table.
If
you
want
to
actually
store
values,
but
you
don't
need
it
all
necessary
needs
a
neuron
system
or
DHT.
A
A
So
in
a
p2p,
a
public
key
is
represented
by
a
string
like
that
QA
q,
mu,
tah,
etc,
etc,
and
the
format
of
this
is
basically
the
hash
of
a
small
data
structure
containing
a
public
key
which
can
be
our
Saed
251,
9
or
secti,
or
any
asymmetric
encryption
that
exists.
It's
designed
to
be
very
extensible
in
any
p2p,
and
this
is
strictly
enforced
so
that
you
cannot
prove
you
cannot
steal
someone's
identity.
A
You
need
to
prove
that
you
are
the
owner
of
a
public
key
when
someone
connects
to
you
and
the
fact
that
this
is
the
identity
of
a
node
makes
it
possible
to
be
the
reputation
system
on
this.
Just
like
on
a
public
forum.
Imagine
you
register
to
a
forum,
you
choose
a
nickname
and
then
you
pose
to
become
popular,
etcetera,
etcetera
and
people
get
interest
in
you.
We
do
the
same
in
peer-to-peer
system.
A
Sorry
I
said
I
was
sick,
so
I'm
going
to
cough
a
lot
and
I
apologize.
Another
second
component
in
a
peer-to-peer
system
is
the
peer
discovery
mechanism.
So
imagine
you
create
a
network.
You
want
people
to
connect
to
it,
but
how
does
that
work?
People
need
to
know
your
programs
to
know
how
to
connect
to
a
network,
and
we
have
various
ways
to
do
that.
You
can
first
of
all
discover
the
nodes.
What
are
on
same
network
as
you
and
to
do
that
we
use
em,
DNS
or
DNS
as
do
so.
A
The
way
this
works
is
you
just
broadcast
a
message
over
UDP
on
the
UDP
multicast
IP
and
every
node
on
the
network
receives
this
message
and
broadcast
the
IP,
and
so
no
just
discover
each
other
and
connect
to
each
other.
That's
how
you
do
on
a
local
network.
You
cannot
do
that
on
the
internet
because
you
cannot
just
broadcast
a
message
on
the
entire
internet.
That's
not
going
to
work
so
to
do
that
to
connect
to
network
on
the
Internet.
A
We
need
bootstrap
nodes,
which
are
an
IP
address,
which
we
hard
code
inside
the
program
and
the
program
just
connects
to
them.
You're
going
to
say,
that's
pretty
centralized
me
to
hard-code
IP
addresses
in
a
program,
but
we
have
no
other
choice.
Unfortunately,
so
that's
a
hack,
but
we
have
no
other
way
right
now
and
that's
the
first
step.
You
know
that's
what
gets
you
on
the
network,
but
once
you
are
connected,
you
can
just
broadcast
messages
to
the
nodes
you
are
connected
to
and
share
information
about
the
network
information
on
the
topology.
A
You
discover
the
rest
of
a
network
and
then
you
build
your
whole
network
and
you
connect
to
thousands
of
other
peers.
Once
you
are
connected
third
element,
you
can
start
broadcasting
messages.
So
why
do
you
want
to
broadcast
messages?
For
example
in
your
chat
application?
Imagine
your
network
is
just
simple
chatting
every
time
you
type
in
research,
you
broadcast
it
to
everyone.
That's
the
first
example
second
example
in
blockchain
technologies.
A
So
if
you
are
familiar
with
ipfs,
ipfs
is
a
way
of
distributing
data
and
ipfs
is
based
on
a
hash
table
and,
more
specifically
on
Kadima,
which
is
the
most
popular
hike
algorithm
for
hash
tables.
And
what
is
the
hash
table?
It's
basically
the
same
as
a
house
as
a
hash
map
in
rust,
which
associate
keys
with
values,
just
a
key
value
store.
Each
Key
has
an
Associated
value.
A
The
difference
is
that
in
a
distributed
hash
table,
as
its
name
says
it's
distributed,
which
means
that
each
node
on
his
toes
a
partial
view
of
hash
table
so
and
to
determine
which
value
you
store.
You
don't
saw
everything
you
install
a
partial
set,
the
determine
which
values
you
store.
You
use
your
public
key,
which
I
explained
three
size
ago.
A
You
saw
up
to
20
values
and,
to
the
word
sorry
use
the
distance
between
your
public
key
and
bikini
to
store,
so
he
store
up
to
20
values
which
have
one
bit
of
difference
between
your
PID
and
working.
You
store
plus
up
to
20
values,
whose
he
is
two
bits
away
from
your
PID
and
so
on
and
so
forth,
which
means
that,
in
order
to
determine
where
to
find
a
value,
you
find
the
nodes
whose
public
key
is
close
to
the
value,
and
you
just
ask
these
nodes
for
the
public
key.
A
The
drawback
of
a
DHT
is
that
it's
quite
easy
to
attack.
Unfortunately,
this
whole
system
assumed
that
the
whole
network
is
not
malicious,
but
everyone's
plays
the
game
and
there's
a
lot
of
research
being
done
about
how
to
make
this
more
robust.
But
right
now
we
have
no
solution
and
yeah,
that's
also
a
hack.
We
are
researching
how
to
do
that.
Better
and
I
showed
the
little
diagram
underneath
to
explain
so
these
pakoras
great,
but,
for
example,
in
a
th
TV
Snowden
story,
is
to
value
of,
is
snowed
on.
A
A
So
what
lipid
B
is
is
a
framework
library
designed
by
company
protocol
labs.
That's
the
company
that
managed
with
specifications
that
people
who
created
it
initially
and
they
are
designing
it
as
well.
You
can
find
more
information
on
the
p2p
dot
io.
The
origin
of
the
p2p
is
that
it's,
it
was
the
networking
system,
ipfs
and
ipfs
uses,
go
and
Jas
implementations
which
were
initially
part
of
ifs
and
were
extracted
into
their
own
Finland
named
nippy.
A
To
be
what
we've
been
doing
at
parity
is
write
the
rest
implementation
and,
what's
what
I'm
present
in
today,
you
can
find
the
link
on
github
there
we
started
with
one
year
ago,
approximately
in
October
I
think
it's
almost
ready
to
be
published.
We
are
going
to
publish
version
0.1
next
year,
but
it's
like
a
polished
version.
It's
not
like
a
first
draft,
but
we
just
quickly
publish
it's
something,
that's
supposed
to
actually
work.
If
it
doesn't
please
file
issues,
but
only
beginning
of
next
year,
it
uses
Tokyo.
A
We
want
it
to
be
as
fast
as
possible.
We
wanted
to
be
asynchronous.
We
want
to.
We
want
it
to
be
possible.
We
have
hundreds
of
nodes
connected
to
your
machine
without
any
performance
issue,
hopefully,
and
we're
using
it
already
at
parity
in
what
we
call
it.
Substrate
and
polka
dots,
I,
don't
know
if
you
heard
of
substrate
and
polka
dot,
we
are
blockchain
technologies
and
the
p2p
is
the
value
networking
system
of
substrate
and
polka
dot,
and
you
can
see
it
in
our
at
telemetry
that
polka
dot
IO.
A
A
We
have
approximately
70
nodes
in
workout
right
now,
which
is
not
a
lot,
but
you
can
just
write
out
and
see
how
much
we
can
grow
the
network
without
it
crashing,
and
we
are
betting
on
the
p2p,
because
a
lot
of
people
actually
betting,
only
p2p
if
you
on
2.0,
is
probably
going
to
use
the
p2p
and
that,
like
triggered
the
chain
reaction,
a
lot
of
people
who
are
in
the
few
meters
ecosystem
are
also
going
to
bet
on
the
p2p.
Because
of
that,
it's
like
a
really
growing
thing
and
the
good
point
about
everyone.
A
A
And
before
going
further
I
invite
you,
if
you
have
a
laptop
on
you,
you
can
try
it
out
now.
I
would
be
pleased
if
some
of
you
did
by
typing
this
command.
Cargo,
install
I,
hope,
I,
hope.
You
trust
me
to
not
have
put
a
malicious
piece
of
code
in
there,
but
if,
if
you
laptop
starts
crushing
or
something
you
can
find
me
afterwards
and
beat
me
down,
so
if
you
want
to
try
it
out
type
cargo
install
with
this
get
URL
and
then
run
it
with
rest
rush
demo
or
do
I
tell.
A
I
mean
to
Mecca
and
I'm,
going
to
wait
for
you
to
type
things.
So
the
way
this
demo
work
is
it's
going
to
find
people
on
the
net
of
the
local
network,
using
n,
DNS,
so
I'm
connected
to
the
Novotel
lobby
Wi-Fi,
but
I
expect
it
to
not
work
properly
and
DNS
here,
necessarily
so.
I
also
created
a
bootstrap
node
on
a
server,
so
it
should
just
work.
If
you
launch
the
demo,
everyone
should
be
able
to
connect
to
each
other.
A
That's
not
decentralized,
since
I
created
the
bootstrap
node,
but
that's
a
workaround
because
I
don't
think
the
Wi-Fi
here
is
reliable
and
also
many
people
on
the
different
Wi-Fi.
So
if
you
connect,
you
should
be
able
to
shut.
You
should
see
my
message
and
I'm
going
to
go
back
to
this
demo
afterwards.
A
So
it's
it
uses
MDM
s
to
discover
local
nodes
is
also
uses
a
bootstrap
node
and
every
single
node
it
discovers
it
tries
to
connect
to
interest
to
maintain
a
connection
to
and
whenever
you
type
a
message
on
the
chat
it
just
broadcasts
with
chat
message
everywhere.
So
everyone
receives
the
message.
Of
course
you
have
no
history.
A
If
you
connect,
you
don't
see
what
people
have
tried
before
you,
you
also
where
you
access
your
UX
is
not
so
great,
and
you
can,
of
course
check
out
the
source
code
but
keep
in
mind,
but
you
are
trying
to
improve
the
API
and
the
source
code
is
quite
messy
right
now,
but
you
can
check
it
out
and
peace
of
warning.
We
haven't
tested
with
the
p2p
with
more
than
approximately
80
nodes,
so
you
might
find
a
bug,
but
hopefully
not
so
I'm,
going
to
continue
I
hope
everyone's
over
URL.
A
So
let's
dive
a
bit
more
into
the
p2p
you,
the
special
things
about
the
p2p
is
that
it's
very
modular
so
we're
not
using
just
an
IP
address
and
a
port
we're
using
what
we
call
the
multi
address.
Instead
of
having
so
just
an
IP
address
and
a
port,
we
have
a
string
IP
for
slash
your
IP
address,
large
tcp,
slash
your
port,
and
the
good
advantage
of
this
is
that
we
can
basically
do
anything
we
want
with,
because
we
just
have
a
string.
So
instead
of
using
TCP,
you
can
use
UDP.
A
You
can
use
quake
on
top
of
UDP.
You
can
use
ipv6,
you
can
use
WebSockets
well.
Further
example
has
a
/ws
which
means
put
WebSockets
on
top
of
his
TCP
connection,
and
why
do
we
want
WebSockets?
Are
you
going
to
ask
because
browsers
can
only
use
WebSockets
and
a
use
case
of
Lippe
TP?
Is
we
want
it
to
run
inside
of
a
browser
and
it
works
right
now
you
can
compile
a
p2p
and
run
it
in
a
browser
and
connect
to
other
nodes,
which
is
quite
nice,
I.
Think
so.
A
Right
now
rest
a
bit
visible,
TCP
WebSockets
DNS.
You
can
put
a
DNS
domain
name
and
UNIX
domain
sockets,
that's
obviously
disabled
by
default,
because
you
don't
want
to
tell
another
node
to
connect
through
its
local
socket.
That's
not
very
secure,
but
it's
supported
in
the
future
and
in
the
future
we
very
want.
We
want
very
much
quick,
which
is
the
protocol
design
by
Google
on
top
of
UDP.
A
A
Here
is
an
overview
of
a
riot
of
protocol
on
the
wire.
So
what
happens
when
two
nodes
connect,
so
they
use
a
transport,
a
multi
address
to
decide
how
to
connect
to
each
other.
The
tcp/ip
web
socket
what
I
just
explained
then,
once
they
connect,
they
negotiate
an
encryption
protocol
to
make
sure
that
the
PRI
disconnect
is
correct.
Sorry,
on
top
of
its
encryption
layer,
we're
using
a
multiplexing
protocol
so
that
you
can
divide
your
connection
into
multiple
sub
streams.
A
A
So,
even
though
protocol
labs
designing
the
thing,
it's
only,
the
only
important
part
is
the
core
of
the
p2p.
On
top
of
that,
you
can
just
design
your
own
protocol.
You
can
do
whatever
you
want
once
you
have
encryption
and
multiplexing
and
just
create
whatever
you
put
protocol.
You
want.
On
top
of
that,
the
p2p
doesn't
assume
that
any
proto
writes
about
it.
You
can
just
pass
any
protocol
name
and,
if
you're,
if
a
remote,
supports
the
protocol,
it's
going
to
accept
and
start
speaking
your
protocol.
A
So
you
can
just
create
your
own
network
with
whatever
protocol
you
want,
and
this
is
really
cool,
even
if
you
know
in
advance
which
protocol
you
support
its
they're,
pretty
nice
to
be
able
to
experiment
with
new
stuff.
Imagine
you
want
to
replace
a
protocol
with
another
you'd
create
your
new
protocol.
You
add
support
for
both
and
then
you
remove
a
deprecated
one
life
without
having
to
do
a
breaking
change
and
that's
it
I'm
going
to
switch
back
to
the
demo.
A
B
A
We
don't
have
any
protection
I
against
poison.
Unfortunately,
we
actually
had
so
when
using
the
p2p
in
substrate
right
now
and
ipfs
also
uses
the
p2p
and
to
give
you
an
example,
but
yet
is
accidentally
merged
once,
which
means
that
substrate
got
polluted
by
ipfs
and
ipfs
got
polluted
by
substrate,
and
that
was
really
nasty
because
substrate
just
stopped
working
because
of
that
is
basically
an
attack
but
involuntary,
and
we
don't
we
didn't.
We
don't
know
how
to
fix
that.
Yet,
like
its
undoing
research
like
protocol
abs
is
actively
researching
how
to
fix
that.
A
So
so
I
have
a
bonus
night,
I
kind
of
unseated
this
we
so
right
now.
All
we
do
is
whenever
you
connect
to
the
network,
whenever
you
dial
a
node,
you
ask
which
IP
other
IP
address
is
B
is
yours,
which
gives
you
your
external
IP
address,
and
then
you
advertise
this
IP
to
network.
That's
all.
We
do
right
now
in
the
future.
We're
going
to
do
your
PNP,
but
that's
actually
not
working
in
practice.
That's
working
in
theory,
but
yo
PNP
is
very
crap.
A
A
If
you
need
the
direct
connection
to
a
node
you
use
with
relay
in
practice,
you
probably
don't
really
need
a
lot
of
nut
reversal
because
you
just
broadcast
messages
usually,
and
so
you
don't
ring
the
direct
connection
to
a
node,
a
node
behind
the
knot.
Just
dies,
someone
and
then
broadcast
message
to
is
peer
and
that's
it.
Naturalizer
is
quite
important
for
a
browser
use
case
because
browsers
are
like
behind
the
vitro
and
not
more
or
less
like
the
browser
doesn't
allow
an
incoming
connection.
A
A
The
p2p
doesn't
do
that
directly,
but
would
be
on
top
of
limb.
P2P
we're
just
doing
the
networking,
but
we
expose
everything
you
need
to
do
whatever
you
want.
The
API
should
be
very
flexible.
So
if
you
want
to
keep
your
value
in
store,
just
do
it
manually
like
the
p2p,
is
not
going
to
decide
which
one
used
to
purge
or
to
store
or
blah
blah
blah.
That's
your
program
on
top
of
it.
Okay,.
B
A
A
A
So
the
first
question
is
very
fancy
mean
variance,
so
we're
very
of
the
p2p
is
that
it
was
initially
part
of
ipfs
and
then
it
was
split.
So
the
reference
information
is
with
its
JavaScript
implementation.
Actually
and
proto
grabs,
currently
writing
a
specifications
which
we
are
trying
to
follow,
but
it's
not
complete
it's
an
ongoing
effort.
We
are
recruiting
a
ton
of
people
were
recruiting
technical
writers
to
write
an
actual
specifications,
the
reference
informations
in
JavaScript
right
now
and
we
try
to
follow
it
as
much
as
possible.
A
But
since
it's
code
and
code
is
messy,
we
are
not,
we
are
compatible,
but
we
are
trying
to
be,
and
as
for
the
noise
protocol,
I
don't
know
actually
I'm,
not
for
one
who
designed
this
I
know.
So
we
have
someone
named
Jeff
at
the
web,
free
Foundation,
which
is
friends
with
parity
who
has
been
looking
into
this,
who
opened
a
few
issues
I
think.
So
someone
is
looking
into
that,
but
not
me
personally.
So.
E
A
E
C
E
A
B
E
F
B
A
Unfortunately,
no
I've,
so
the
closest
thing
I
have
to
benchmarking.
I
wrote
small
how
to
say
that
basically,
a
test
I'm
spawning
25
nodes
and
they
all
talk
to
each
other
say
hello
word
to
each
other
and
that
takes
I,
think
30
seconds
or
so
for
to
spawn
25
knows
and
they
flood
each
other's
and
I.
Don't
remember
how
much
data,
which
is
honestly
quite
bad,
but
we
want
to
improve
that,
but
we
haven't
done
that
yet
we
have
taken
over
possible
decisions
to
make
it
fast.
A
F
F
B
F
B
A
So,
right
now,
more
or
less
like
versus
the
negotiation
protocol
is
badly
designed
and
we
are
actually
not
following
the
design
in
order
to
make
it
actually
fast,
but
they
are
fixing
this
basic.
You
cannot
just
assume
that
negotiation
succeeding,
so
you
have
an
extra
round
trip
and
that's
thank
you.
Whoever
did
that
you
can.
You
can
not
just
assume
that
negotiation
is
succeeding,
but
we
are
fixing
that
one
that
has
no
limitation.
The
design.
A
You
can
for
sure
determine
if
a
connection
uses
the
p2p
if
we're
using.
If
we're
going
to
implement
or
maybe
i2p,
maybe
that
will
fix
face.
But
even
that
know
you
can
be
prey.
You
can
pretty
easily
know
that
the
connection
uses
EPP
unless
sorry,
unless
you
use
WebSockets
and
since
it's
encrypted
inside
WebSockets,
you
cannot
tell.