kubo icon indicating copy to clipboard operation
kubo copied to clipboard

bitswap network Nofity Event mat be register After connect nodes

Open songxiang93 opened this issue 3 years ago • 7 comments

Checklist

Installation method

built from source

Version

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

Config

config in private network node

Description

file ipfs_impl.go of [email protected]

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 [email protected]

	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。

songxiang93 avatar Aug 09 '22 09:08 songxiang93

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

welcome[bot] avatar Aug 09 '22 09:08 welcome[bot]

@ppt93 I'm not sure how that an issue here.

Jorropo avatar Aug 09 '22 12:08 Jorropo

@Jorropo

step1: dht query peer and peer connected return result。 step2:bitswap register connected event step3: so bitswap can not deal with this connect event。

we expect that: step1:bitswap register connected event step2: dht query peer and peer connected return result。 step3: bitswap deal with connectd event and new message queue with this connected node。

songxiang93 avatar Aug 09 '22 13:08 songxiang93

@ppt93 the bitswap register only happen the first time when your node starts, for IPFS to find a node before bitswap register the notify you would need to find that node very early in the bootstrap process.

Do you have a real world example where that happen ?

Jorropo avatar Aug 09 '22 13:08 Jorropo

image If I add time.second in this node, the bitswap event register the notifty before node connect so that I can receive have and don not have message. last I can receive block data from connected node.

If I add time.second in this node, the bitswap event register the notifty after node connect so that I can not receive any message from connected node. @Jorropo

songxiang93 avatar Aug 10 '22 02:08 songxiang93

image

songxiang93 avatar Aug 10 '22 02:08 songxiang93

@Jorropo What I mean is that the connect event of bitwap for these nodes will not be triggered again unless these nodes actively connect to this node

songxiang93 avatar Aug 10 '22 02:08 songxiang93