Skip to content

Commit

Permalink
Added HandlePoolJoinRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 7, 2023
1 parent b811009 commit aa0cffd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions announcements/announcements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / unit

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / All

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / All

missing return (compile)

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / Build & check fula mobile for ios

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / Build & check fula mobile for ios

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / unit

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / All

missing return

Check failure on line 94 in announcements/announcements.go

View workflow job for this annotation

GitHub Actions / All

missing return (compile)

func (an *FxAnnouncements) HandleAnnouncements(ctx context.Context) {
defer an.wg.Done()
for {
Expand Down Expand Up @@ -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)
}
}

Expand Down
18 changes: 18 additions & 0 deletions blockchain/bl_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

0 comments on commit aa0cffd

Please sign in to comment.