blob: 0cf40181dc0f32ba1d4271cb717b39fb78e3bb38 [file] [log] [blame]
Bogdan Caprita3c319212015-08-19 18:12:53 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package discovery
6
7import (
8 "v.io/v23/context"
9 "v.io/v23/discovery"
10 "v.io/v23/security/access"
Jungho Ahn24112322015-09-15 10:10:24 -070011 "v.io/v23/verror"
12)
13
14var (
15 errNoInterfaceName = verror.Register(pkgPath+".errNoInterfaceName", verror.NoRetry, "{1:}{2:} interface name not provided")
16 errNoAddresses = verror.Register(pkgPath+".errNoAddress", verror.NoRetry, "{1:}{2:} address not provided")
Bogdan Caprita3c319212015-08-19 18:12:53 -070017)
18
19// Advertise implements discovery.Advertiser.
Jungho Ahnd5871542015-09-08 18:48:11 -070020//
21// TODO(jhahn): Handle ACL.
Bogdan Caprita3c319212015-08-19 18:12:53 -070022func (ds *ds) Advertise(ctx *context.T, service discovery.Service, perms access.Permissions) error {
Jungho Ahn24112322015-09-15 10:10:24 -070023 if len(service.InterfaceName) == 0 {
24 return verror.New(errNoInterfaceName, ctx)
25 }
26 if len(service.Addrs) == 0 {
27 return verror.New(errNoAddresses, ctx)
28 }
29
Jungho Ahnd5871542015-09-08 18:48:11 -070030 if len(service.InstanceUuid) == 0 {
31 service.InstanceUuid = NewInstanceUUID()
32 }
33 ad := &Advertisement{
34 ServiceUuid: NewServiceUUID(service.InterfaceName),
35 Service: service,
36 }
37 ctx, cancel := context.WithCancel(ctx)
38 for _, plugin := range ds.plugins {
39 err := plugin.Advertise(ctx, ad)
40 if err != nil {
41 cancel()
42 return err
43 }
44 }
Bogdan Caprita3c319212015-08-19 18:12:53 -070045 return nil
46}