Skip to content
Snippets Groups Projects
Commit 69e1a67a authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Move poll logic to comms

parent 51325fca
No related branches found
No related tags found
No related merge requests found
......@@ -17,9 +17,8 @@ package io
import (
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/notificationsBot"
"gitlab.com/xx_network/comms/connect"
"google.golang.org/grpc"
)
......@@ -34,46 +33,19 @@ type PollingConn interface {
// with a protocomms object.
type NdfPoller struct {
permHost *connect.Host
pc *connect.ProtoComms
pc *notificationsBot.Comms
}
// NewNdfPoller creates a new permconn object with a host and protocomms id.
func NewNdfPoller(pc *connect.ProtoComms, permHost *connect.Host) NdfPoller {
func NewNdfPoller(pc *notificationsBot.Comms, pHost *connect.Host) NdfPoller {
return NdfPoller{
pc: pc,
permHost: permHost,
permHost: pHost,
}
}
// PollNdf gets the NDF from the Permissioning server.
func (p NdfPoller) PollNdf() (*pb.NDF, error) {
func (p NdfPoller) PollNdf(ndfHash []byte) (*pb.NDF, error) {
permHost := p.permHost
// Create the Send Function
f := func(conn *grpc.ClientConn) (*any.Any, error) {
// Set up the context
ctx, cancel := connect.MessagingContext()
defer cancel()
// We use an empty NDF Hash to request an NDF
ndfRequest := &pb.NDFHash{Hash: make([]byte, 0)}
// Send the message
clientConn := pb.NewRegistrationClient(conn)
resultMsg, err := clientConn.PollNdf(ctx, ndfRequest)
if err != nil {
return nil, errors.New(err.Error())
}
return ptypes.MarshalAny(resultMsg)
}
// Execute the Send function
jww.TRACE.Printf("Sending Request Ndf message...")
resultMsg, err := p.pc.Send(permHost, f)
if err != nil {
return nil, err
}
result := &pb.NDF{}
err = ptypes.UnmarshalAny(resultMsg, result)
return result, err
return pc.PollNdf(permHost, ndfHash)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment