Connect connects a gateway by its identifiers to the Gateway Server, and returns a io.Connection for traffic and control.
( ctx context.Context, frontend io.Frontend, ids *ttnpb.GatewayIdentifiers, addr *ttnpb.GatewayRemoteAddress, opts ...io.ConnectionOption, )
| 578 | // Connect connects a gateway by its identifiers to the Gateway Server, and returns a io.Connection for traffic and |
| 579 | // control. |
| 580 | func (gs *GatewayServer) Connect( |
| 581 | ctx context.Context, |
| 582 | frontend io.Frontend, |
| 583 | ids *ttnpb.GatewayIdentifiers, |
| 584 | addr *ttnpb.GatewayRemoteAddress, |
| 585 | opts ...io.ConnectionOption, |
| 586 | ) (*io.Connection, error) { |
| 587 | if err := gs.AssertGatewayRights(ctx, ids, ttnpb.Right_RIGHT_GATEWAY_LINK); err != nil { |
| 588 | return nil, err |
| 589 | } |
| 590 | |
| 591 | uid := unique.ID(ctx, ids) |
| 592 | logger := log.FromContext(ctx).WithFields(log.Fields( |
| 593 | "protocol", frontend.Protocol(), |
| 594 | "gateway_uid", uid, |
| 595 | "gateway_ip_address", addr.Ip, |
| 596 | )) |
| 597 | ctx = log.NewContext(ctx, logger) |
| 598 | |
| 599 | var isAuthenticated bool |
| 600 | if _, err := rpcmetadata.WithForwardedAuth(ctx, gs.AllowInsecureForCredentials()); err == nil { |
| 601 | isAuthenticated = true |
| 602 | } |
| 603 | gtw, err := gs.entityRegistry.Get(ctx, &ttnpb.GetGatewayRequest{ |
| 604 | GatewayIds: ids, |
| 605 | FieldMask: ttnpb.FieldMask( |
| 606 | "administrative_contact", |
| 607 | "antennas", |
| 608 | "attributes", |
| 609 | "disable_packet_broker_forwarding", |
| 610 | "downlink_path_constraint", |
| 611 | "enforce_duty_cycle", |
| 612 | "frequency_plan_id", |
| 613 | "frequency_plan_ids", |
| 614 | "gateway_server_address", |
| 615 | "location_public", |
| 616 | "require_authenticated_connection", |
| 617 | "schedule_anytime_delay", |
| 618 | "schedule_downlink_late", |
| 619 | "status_public", |
| 620 | "technical_contact", |
| 621 | "update_location_from_status", |
| 622 | ), |
| 623 | }) |
| 624 | if errors.IsNotFound(err) { |
| 625 | if gs.requireRegisteredGateways { |
| 626 | return nil, errGatewayNotRegistered.WithAttributes("gateway_uid", uid).WithCause(err) |
| 627 | } |
| 628 | fpID, ok := frequencyplans.FallbackIDFromContext(ctx) |
| 629 | if !ok { |
| 630 | return nil, errNoFallbackFrequencyPlan.WithAttributes("gateway_uid", uid) |
| 631 | } |
| 632 | logger.Warn("Connect unregistered gateway") |
| 633 | gtw = &ttnpb.Gateway{ |
| 634 | Ids: ids, |
| 635 | FrequencyPlanId: fpID, |
| 636 | FrequencyPlanIds: []string{fpID}, |
| 637 | EnforceDutyCycle: true, |
nothing calls this directly
no test coverage detected