README.md 5.81 KB
Newer Older
1
[libp2p](https://github.com/libp2p/specs) implementation in Go.
2
===================
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
3
4

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
5
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
keks's avatar
keks committed
6
7
[![GoDoc](https://godoc.org/github.com/ipfs/go-libp2p?status.svg)](https://godoc.org/github.com/libp2p/go-libp2p)
[![Build Status](https://travis-ci.org/ipfs/go-libp2p.svg?branch=master)](https://travis-ci.org/libp2p/go-libp2p)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8

9
10
11
<p align="center">
  <img src="https://github.com/libp2p/libp2p/raw/master/logo/libp2p-logo.png" />
</p>
David Dias's avatar
David Dias committed
12

13
14
15
16
> libp2p implementation in Go

# Description

17
[libp2p](https://github.com/libp2p/specs) is a networking stack and library modularized out of [The IPFS Project](https://github.com/ipfs/ipfs), and bundled separately for other tools to use.
18

19
> libp2p is the product of a long, and arduous quest of understanding -- a deep dive into the internet's network stack, and plentiful peer-to-peer protocols from the past. Building large scale peer-to-peer systems has been complex and difficult in the last 15 years, and libp2p is a way to fix that. It is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.
20

21
This is the entry point for the Go implementation of `libp2p`, which is formed by multiple modules, usually accessible under the `github.com/libp2p/go-libp2p-*` namespace.
22

23
24
# Usage

25
The vast majority of `go-libp2p` modules live in their own repositories. This repository is the apex of the Go `libp2p` stack, and primarily serves to track the working-version set of all the different modules.
26

27
28
29
30
31
32
33
34
35
This is done using [Gx](https://github.com/whyrusleeping/gx) and its companion [Gx-go](https://github.com/whyrusleeping/gx-go).

The [`package.json`](https://github.com/libp2p/go-libp2p/blob/master/package.json) file maintains the current list of dependencies which, when used, provide a working version of the stack.

**Any `go-libp2p` application (including the examples in this repository) need to have their imports rewritten with Gx, otherwise compilation will fail.**

The process to get `go-libp2p` working in your project is as follows:

* Make sure you install Gx and Gx-go:
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
go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go
```

* Initialize Gx in the base folder of your project's repository. This will create a `package.json` file:

```
gx init
```

* Import `go-libp2p` to your project. This will import `go-libp2p` on its latest published version:

```
gx import github.com/libp2p/go-libp2p
```

* Download and install all the `go-libp2p` dependencies:

```
gx install --verbose --global
```

* Write your `go-libp2p` code normally and use regular imports (i.e. `import "github.com/libp2p/go-libp2p-net"`)
* Before compiling, run a Gx-go-rewrite command in the base folder of your repository: You will see that your `go-libp2p-*` imports have been rewritten to something like `gx/ipfs/QmVtMT3fD7DzQNW7hdm6Xe6KPstzcggrhNpeVZ4422UpKK/go-libp2p-net`:

```
gx-go rewrite
```

* With the imports rewritten, you can now compile your `go-libp2p`. If you don't rewrite your imports, your build will error as `go-libp2p` does not build on master.
* Before committing, it is customary to undo the rewrites with:

```
gx-go rewrite --undo
```

Most projects include these steps in a `Makefile` for convenience. [Here is an example](https://github.com/libp2p/go-libp2p-raft/blob/master/Makefile).


# Contribute

libp2p implementation in Go is a work in progress. As such, there's a few things you can do right now to help out:
 - Go through the modules below and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrasture behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
 - **Perform code reviews**.
 - **Add tests**. There can never be enough tests.

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
84

David Dias's avatar
David Dias committed
85
86
# Examples

87
Examples and information on how to run them can be found on the [examples folder](examples) and their respective READMEs.
David Dias's avatar
David Dias committed
88

89
# Run tests
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
90

91
```bash
zjiekai's avatar
zjiekai committed
92
$ cd $GOPATH/src/github.com/libp2p/go-libp2p
Jeromy Johnson's avatar
Jeromy Johnson committed
93
94
$ make deps
$ go test ./p2p/<path of module you want to run tests for>
95
```
96

Jeromy Johnson's avatar
Jeromy Johnson committed
97
## Links
98
- [**Specs**](https://github.com/libp2p/specs)
99
- [**Website**](https://github.com/libp2p/website)
Lars Gierth's avatar
Lars Gierth committed
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


## Extracting packages from go-libp2p

We want to maintain history, so we'll use git-subtree for extracting packages.

```sh
# 1) create the extracted tree (has the directory specified as -P as its root)
> cd go-libp2p/
> git subtree split -P p2p/crypto/secio/ -b libp2p-secio
62b0a5c21574bcbe06c422785cd5feff378ae5bd
# important to delete the tree now, so that outdated imports fail in step 5
> git rm -r p2p/crypto/secio/
> git commit
> cd ../

# 2) make the new repo
> mkdir go-libp2p-secio
> cd go-libp2p-secio/
> git init && git commit --allow-empty

# 3) fetch the extracted tree from the previous repo
> git remote add libp2p ../go-libp2p
> git fetch libp2p
> git reset --hard libp2p/libp2p-secio

# 4) update self import paths
> sed -someflagsidontknow 'go-libp2p/p2p/crypto/secio' 'golibp2p-secio'
> git commit

# 5) create package.json and check all imports are correct
> vim package.json
> gx --verbose install --global
> gx-go rewrite
> go test ./...
> gx-go rewrite --undo
> git commit

# 4) make the package ready
> vim README.md LICENSE
> git commit

# 5) bump the version separately
> vim package.json
> gx publish
> git add package.json .gx/
> git commit -m 'Publish 1.2.3'

# 6) clean up and push
> git remote rm libp2p
> git push origin master
```