ipfs / ipfs/kubo

bitswap network Nofity Event mat be register After connect nodes

Open
#9,175 7 comments 0 reactions 0 assignees View on GitHub
kind/bug need/triage
Dominant language
Go
Stars
17.1k
Forks
3.2k
Avg merge
3d 18h
Merged PRs (30d)
11

Description

### Checklist

- [X] This is a bug report, not a question. Ask questions on [discuss.ipfs.io](https://discuss.ipfs.io).
- [X] I have searched on the [issue tracker](https://github.com/ipfs/kubo/issues?q=is%3Aissue) for my bug.
- [X] I am running the latest [kubo version](https://dist.ipfs.io/#kubo) or have an issue updating.

### Installation method

built from source

### Version

```Text
Kubo version: 0.14.0
Repo version: 12
System version: amd64/windows
Golang version: go1.17.10
```

### Config

```json
config in private network node
```

### Description

file ipfs_impl.go of go-bitswap@0.7.0
```
func (bsnet *impl) Start(r Receiver) {
bsnet.receiver = r
bsnet.connectEvtMgr = newConnectEventManager(r)
for _, proto := range bsnet.supportedProtocols {
bsnet.host.SetStreamHandler(proto, bsnet.handleNewStream)
}

bsnet.host.Network().Notify((*netNotifiee)(bsnet))
bsnet.connectEvtMgr.Start()

}
```
It seem that Notify event of bsnet may be happen after the dial result return of the code:
```
bsnet.host.Network().Notify((*netNotifiee)(bsnet))
```

`conn, err := w.s.addConn(res.Conn, network.DirOutbound)`

file dial_worker.go of go-libp2p@v0.20.3
```
if res.Conn != nil {
// we got a connection, add it to the swarm

//debug.PrintStack()
//time.Sleep(time.Second*1)
conn, err := w.s.addConn(res.Conn, network.DirOutbound)
if err != nil {
// oops no, we failed to add it to the swarm
res.Conn.Close()
w.dispatchError(ad, err)
continue loop
}

// dispatch to still pending requests
for _, reqno := range ad.requests {
pr, ok := w.requests[reqno]
if !ok {
// it has already dispatched a connection
continue
}

pr.req.resch <- dialResponse{conn: conn}
delete(w.requests, reqno)
}

ad.conn = conn
ad.requests = nil

continue loop
}

```
So the bsnet may not feel this connection event unless disconect and connect again。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.