From aa0cffd90c85ac3ddd95b021317bad84df8c6a79 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Mon, 6 Nov 2023 19:41:56 -0500 Subject: [PATCH] Added HandlePoolJoinRequest --- announcements/announcements.go | 12 ++++++++++++ blockchain/bl_pool.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/announcements/announcements.go b/announcements/announcements.go index aeaad9f4..7ff2fa89 100644 --- a/announcements/announcements.go +++ b/announcements/announcements.go @@ -82,6 +82,17 @@ func (an *FxAnnouncements) Start(ctx context.Context, validator pubsub.Validator return nil } +func (an *FxAnnouncements) processAnnouncement(ctx context.Context, from peer.ID, atype AnnouncementType) error { + switch atype { + case IExistAnnouncementType: + log.Debug("IExist request") + case PoolJoinRequestAnnouncementType: + log.Debug("PoolJoin request") + default: + log.Debug("Unknown request") + } +} + func (an *FxAnnouncements) HandleAnnouncements(ctx context.Context) { defer an.wg.Done() for { @@ -114,6 +125,7 @@ func (an *FxAnnouncements) HandleAnnouncements(ctx context.Context) { } an.h.Peerstore().AddAddrs(from, addrs, peerstore.PermanentAddrTTL) log.Infow("received announcement", "from", from, "self", an.h.ID(), "announcement", a) + an.processAnnouncement(ctx, from, a.Type) } } diff --git a/blockchain/bl_pool.go b/blockchain/bl_pool.go index f5c8ae96..cadbd75a 100644 --- a/blockchain/bl_pool.go +++ b/blockchain/bl_pool.go @@ -9,6 +9,7 @@ import ( "io" "net/http" + "github.com/functionland/go-fula/common" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" ) @@ -340,3 +341,20 @@ func (bl *FxBlockchain) PoolLeave(ctx context.Context, to peer.ID, r PoolLeaveRe return b, nil } } + +func (bl *FxBlockchain) HandlePoolJoinRequest(ctx context.Context, from peer.ID, topicString string) error { + err := bl.FetchUsersAndPopulateSets(ctx, topicString) + if err != nil { + return err + } + status, exists := bl.GetMemberStatus(from) + if !exists { + return fmt.Errorf("peerID does not exists in the list of pool requests or poool members: %s", from) + } + if status == common.Pending { + + } else { + return fmt.Errorf("peerID does not exists in the list of pool requests: %s with status %d", from, status) + } + return nil +}