| package main |
| |
| import ( |
| "context" |
| "fmt" |
| "time" |
| |
| pb "code.hackerspace.pl/hscloud/bgpwtf/cccampix/proto" |
| "code.hackerspace.pl/hscloud/bgpwtf/cccampix/verifier/model" |
| "code.hackerspace.pl/hscloud/go/pki" |
| "google.golang.org/grpc" |
| ) |
| |
| type peeringDB struct { |
| pdb pb.PeeringDBProxyClient |
| } |
| |
| func newPeeringDB(addr string) (processor, error) { |
| conn, err := grpc.Dial(addr, pki.WithClientHSPKI()) |
| if err != nil { |
| return nil, fmt.Errorf("could not connect to peeringdb service: %v", err) |
| } |
| |
| return &peeringDB{ |
| pdb: pb.NewPeeringDBProxyClient(conn), |
| }, nil |
| } |
| |
| func (p *peeringDB) Name() string { |
| return "PeeringDB" |
| } |
| |
| func (p *peeringDB) NextRun(now time.Time, lastFailed bool) time.Time { |
| if lastFailed { |
| return now.Add(1 * time.Minute) |
| } |
| return now.Add(5 * time.Minute) |
| } |
| |
| func (p *peeringDB) RunAll(ctx context.Context, m model.Model) error { |
| id := int64(2641) |
| req := &pb.GetIXMembersRequest{ |
| Id: id, |
| } |
| |
| res, err := p.pdb.GetIXMembers(ctx, req) |
| if err != nil { |
| return fmt.Errorf("GetIXMembers(%d): %v", id, err) |
| } |
| |
| err = m.RecordPeeringDBPeers(ctx, res.Members) |
| if err != nil { |
| return fmt.Errorf("RecordPeeringDBPeers: %v", err) |
| } |
| err = m.RecordPeeringDBPeerRouters(ctx, res.Members) |
| if err != nil { |
| return fmt.Errorf("RecordPeeringDBPeerRouters: %v", err) |
| } |
| return nil |
| } |