Some more occurences of /ipfs

and use  SwapToP2pMultiaddrs (very helpful since ipfs still send
addresses with `/ipfs` tag)
This commit is contained in:
Kishan Mohanbhai Sagathiya 2019-08-15 16:49:26 +05:30
parent c6192cebf4
commit 6656b80a00
14 changed files with 17 additions and 13 deletions

View File

@ -349,7 +349,7 @@ func IsPeerAddress(addr ma.Multiaddr) bool {
if addr == nil {
return false
}
pid, err := addr.ValueForProtocol(ma.P_IPFS)
pid, err := addr.ValueForProtocol(ma.P_P2P)
dnsaddr, err2 := addr.ValueForProtocol(madns.DnsaddrProtocol.Code)
return (pid != "" && err == nil) || (dnsaddr != "" && err2 == nil)
}

View File

@ -228,7 +228,7 @@ func TestDNSMultiaddress(t *testing.T) {
}
func TestPeerAddress(t *testing.T) {
peerAddr, _ := ma.NewMultiaddr("/dns4/localhost/tcp/1234/ipfs/QmP7R7gWEnruNePxmCa9GBa4VmUNexLVnb1v47R8Gyo3LP")
peerAddr, _ := ma.NewMultiaddr("/dns4/localhost/tcp/1234/p2p/QmP7R7gWEnruNePxmCa9GBa4VmUNexLVnb1v47R8Gyo3LP")
cfg := &Config{
APIAddr: peerAddr,
Host: "localhost",

View File

@ -481,7 +481,7 @@ func (api *API) runLibp2pServer(ctx context.Context) {
listenMsg := ""
for _, a := range api.host.Addrs() {
listenMsg += fmt.Sprintf(" %s/ipfs/%s\n", a, api.host.ID().Pretty())
listenMsg += fmt.Sprintf(" %s/p2p/%s\n", a, api.host.ID().Pretty())
}
logger.Infof("REST API (libp2p-http): ENABLED. Listening on:\n%s\n", listenMsg)

View File

@ -18,7 +18,7 @@ import (
var testTime = time.Date(2017, 12, 31, 15, 45, 50, 0, time.UTC)
var testMAddr, _ = ma.NewMultiaddr("/ip4/1.2.3.4")
var testMAddr2, _ = ma.NewMultiaddr("/dns4/a.b.c.d")
var testMAddr3, _ = ma.NewMultiaddr("/ip4/127.0.0.1/tcp/8081/ws/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd")
var testMAddr3, _ = ma.NewMultiaddr("/ip4/127.0.0.1/tcp/8081/ws/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd")
var testCid1, _ = cid.Decode("QmP63DkAFEnDYNjDYBpyNDfttu1fvUw99x1brscPzpqmmq")
var testCid2, _ = cid.Decode("QmYCLpFCj9Av8NFjkQogvtXspnTDFWaizLpVFEijHTH4eV")
var testCid3, _ = cid.Decode("QmZmdA3UZKuHuy9FrWsxJ82q21nbEh97NUnxTzF5EHxZia")

View File

@ -31,7 +31,7 @@ func StringsToPeers(strs []string) []peer.ID {
}
// MustLibp2pMultiaddrJoin takes a LibP2P multiaddress and a peer ID and
// encapsulates a new /ipfs/<peerID> address. It will panic if the given
// encapsulates a new /p2p/<peerID> address. It will panic if the given
// peer ID is bad.
func MustLibp2pMultiaddrJoin(addr Multiaddr, p peer.ID) Multiaddr {
v := addr.Value()

View File

@ -120,7 +120,7 @@ func NewCluster(
listenAddrs := ""
for _, addr := range host.Addrs() {
listenAddrs += fmt.Sprintf(" %s/ipfs/%s\n", addr, host.ID().Pretty())
listenAddrs += fmt.Sprintf(" %s/p2p/%s\n", addr, host.ID().Pretty())
}
logger.Infof("IPFS Cluster v%s listening on:\n%s\n", version.Version, listenAddrs)

View File

@ -88,6 +88,8 @@ func checkErr(doing string, err error) {
func main() {
ctx := context.Background()
ma.SwapToP2pMultiaddrs()
app := cli.NewApp()
app.Name = programName
app.Usage = "CLI for IPFS Cluster"

View File

@ -52,6 +52,8 @@ func daemon(c *cli.Context) error {
logger.Info("Initializing. For verbose output run with \"-l debug\". Please wait...")
ma.SwapToP2pMultiaddrs()
ctx, cancel := context.WithCancel(context.Background())
bootstraps := parseBootstraps(c.StringSlice("bootstrap"))

View File

@ -95,7 +95,7 @@ $ ipfs-cluster-service daemon
Launch a peer and join existing cluster:
$ ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.2/tcp/9096/ipfs/QmPSoSaPXpyunaBwHs1rZBKYSqRV4bLRk32VGYLuvdrypL
$ ipfs-cluster-service daemon --bootstrap /ip4/192.168.1.2/tcp/9096/p2p/QmPSoSaPXpyunaBwHs1rZBKYSqRV4bLRk32VGYLuvdrypL
`,
programName,
programName,

View File

@ -542,7 +542,7 @@ func (cc *Consensus) Peers(ctx context.Context) ([]peer.ID, error) {
}
func parsePIDFromMultiaddr(addr ma.Multiaddr) string {
pidstr, err := addr.ValueForProtocol(ma.P_IPFS)
pidstr, err := addr.ValueForProtocol(ma.P_P2P)
if err != nil {
panic("peer badly encoded")
}

View File

@ -73,7 +73,7 @@ func clusterAddr(c *Cluster) ma.Multiaddr {
for _, a := range c.host.Addrs() {
if _, err := a.ValueForProtocol(ma.P_IP4); err == nil {
p := peer.IDB58Encode(c.id)
cAddr, _ := ma.NewMultiaddr(fmt.Sprintf("%s/ipfs/%s", a, p))
cAddr, _ := ma.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", a, p))
return cAddr
}
}

View File

@ -57,7 +57,7 @@ func New(ctx context.Context, h host.Host, peerstorePath string) *Manager {
}
// ImportPeer adds a new peer address to the host's peerstore, optionally
// dialing to it. The address is expected to include the /ipfs/<peerID>
// dialing to it. The address is expected to include the /p2p/<peerID>
// protocol part or to be a /dnsaddr/multiaddress
// Peers are added with the given ttl.
func (pm *Manager) ImportPeer(addr ma.Multiaddr, connect bool, ttl time.Duration) (peer.ID, error) {

View File

@ -5,8 +5,8 @@ test_description="Test init functionality"
. lib/test-lib.sh
test_expect_success "cluster-service init with --peers succeeds and fills peerstore" '
PEER1=/ip4/192.168.0.129/tcp/9196/ipfs/12D3KooWRN8KRjpyg9rsW2w7StbBRGper65psTZm68cjud9KAkaW
PEER2=/ip4/192.168.0.129/tcp/9196/ipfs/12D3KooWPwrYNj7VficHw5qYidepMGA85756kYgMdNmRM9A1ZHjN
PEER1=/ip4/192.168.0.129/tcp/9196/p2p/12D3KooWRN8KRjpyg9rsW2w7StbBRGper65psTZm68cjud9KAkaW
PEER2=/ip4/192.168.0.129/tcp/9196/p2p/12D3KooWPwrYNj7VficHw5qYidepMGA85756kYgMdNmRM9A1ZHjN
ipfs-cluster-service --config "test-config" init --peers $PEER1,$PEER2 &&
grep -q $PEER1 test-config/peerstore &&
grep -q $PEER2 test-config/peerstore

View File

@ -154,7 +154,7 @@ func (mock *mockCluster) ID(ctx context.Context, in struct{}, out *api.ID) error
// DefaultConfigCrypto,
// DefaultConfigKeyLength)
addr, _ := api.NewMultiaddr("/ip4/127.0.0.1/tcp/4001/ipfs/" + PeerID1.Pretty())
addr, _ := api.NewMultiaddr("/ip4/127.0.0.1/tcp/4001/p2p/" + PeerID1.Pretty())
*out = api.ID{
ID: PeerID1,
//PublicKey: pubkey,