functionland / go-fula

Client-server stack for Web3! Turn your Raspberry Pi to a BAS server in minutes and enjoy the freedom of decentralized Web with a superior user experience!
MIT License
13 stars 6 forks source link

Pubsub #182

Closed ehsan6sha closed 1 year ago

ehsan6sha commented 1 year ago

[X] start a periodic ping [X] update pool_id in config file

[X] create same peerId for both blockchain and fula

[X] When PoolJoin announcement is received it should: [X] 1- add the peerID of announcer to a list and no longer accepts the pubsub [X] 2- call blockchain and checks if it is realy in the list of join requests [X] 3- ping and vote per ping results

[X] on start, if own peerId is in the list of joinrequests also start sending PoolJoinRequest announcement

[X] On join request, updat the members list and add them to peerstore [X] on start, updat the members list and add them to peerstore Ping server node (the one who sent the joinpoolrequest) should: [X] 1- FetchUsersAndPopulateSets with the new pool id when request is made and Update config file with pool id after join request is sent and restart blox service to ensure announcements and actions are done accordingly [X] 2- listen to vote announcements and if more than a threashold start requesting the status of join every x secods and FetchUsersAndPopulateSets if vote went through

[X] Set a timer than if for the last x hours the FetchUsersAndPopulateSets is not called, call it [X] Start voting in the FetchUsersAndPopulateSets. [X] If the members list is empty also call pool/requests endpoint to see who voted and it self voted move status to UnKnown

ehsan6sha commented 1 year ago

We need to make the relay also works with pubsub. Goal: Is to read the nodes that are members of a pool from blockchain API and then create a mesh so that they can exchange messages with each other. The function below is called when blox starts and performs the needed operation: https://github.com/functionland/go-fula/blob/5efbc4c6fd56d5fbfc2130181a4bfe1e35a8973e/blockchain/blockchain.go#L617 Description: We have two types of messages: 1- IExist: This is the one you did (TYPE 1) 2-PoolJoinRequet: This is to notify the peers that are members of the pool that a new node want to join and that they should vote on it (TYPE 2) And Topic is poolID ("1" for example) Issue: Since on the blockchain we store the peerIDs and there is no ip4 address (as it changes) we need to connect with relay. Now I tried two ways to exchange messages and both failed: 1- I tried to add the peers that are read from blockchain to peerstore and without calling host.connect which seems it does not create a mesh as it sometimes complaints that the relay does not support mesh protocols 2- I tried connecting the host peer to each other peer in the same pool. but connection fails with :

2023-11-15T20:48:44.561-0500    DEBUG   fula/blockchain blockchain/blockchain.go:807    Not Connected to peer   {"from": "QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe", "to": "QmPNZMi2LAhczsN2FoXXQng6YFYbSHApuP6RpKuHbBH9eF", "err": "failed to dial QmPNZMi2LAhczsN2FoXXQng6YFYbSHApuP6RpKuHbBH9eF:\n  * [/ip4/3.18.250.172/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] error opening hop stream to relay: failed to dial 12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835:\n  * [/ip4/3.18.250.172/tcp/4001] dial backoff\n  * [/ip4/3.21.220.84/tcp/4001] dial backoff\n  * [/ip4/18.117.52.73/tcp/4001] dial backoff\n  * [/ip4/18.117.52.73/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] error opening hop stream to relay: failed to dial 12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835:\n  * [/ip4/3.18.250.172/tcp/4001] dial backoff\n  * [/ip4/3.21.220.84/tcp/4001] dial backoff\n  * [/ip4/18.117.52.73/tcp/4001] dial backoff\n  * [/ip4/3.21.220.84/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] error opening hop stream to relay: failed to dial 12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835:\n  * [/ip4/3.18.250.172/tcp/4001] dial backoff\n  * [/ip4/3.21.220.84/tcp/4001] dial backoff\n  * [/ip4/18.117.52.73/tcp/4001] dial backoff"}

or

2023-11-15T20:52:33.897-0500    DEBUG   fula/blockchain blockchain/blockchain.go:807    Not Connected to peer   {"from": "QmaUMRTBMoANXqpUbfARnXkw9esfz9LP2AjXRRr7YknDAT", "to": "QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe", "err": "failed to dial QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe:\n  * [/ip4/3.18.250.172/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] error opening relay circuit: NO_RESERVATION (204)\n  * [/ip4/18.117.52.73/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] concurrent active dial through the same relay failed with a protocol error\n  * [/ip4/3.21.220.84/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit] concurrent active dial through the same relay failed with a protocol error"}