Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1 | package ipc |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "io" |
Cosmos Nicolaou | bae615a | 2014-08-27 23:32:31 -0700 | [diff] [blame] | 6 | "net" |
Asim Shankar | b54d764 | 2014-06-05 13:08:04 -0700 | [diff] [blame] | 7 | "reflect" |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 8 | "strings" |
| 9 | "sync" |
| 10 | "time" |
| 11 | |
Jiri Simsa | 519c507 | 2014-09-17 21:37:57 -0700 | [diff] [blame] | 12 | "veyron.io/veyron/veyron2/config" |
| 13 | "veyron.io/veyron/veyron2/context" |
| 14 | "veyron.io/veyron/veyron2/ipc" |
| 15 | "veyron.io/veyron/veyron2/ipc/stream" |
| 16 | "veyron.io/veyron/veyron2/naming" |
Asim Shankar | cc04421 | 2014-10-15 23:25:26 -0700 | [diff] [blame] | 17 | "veyron.io/veyron/veyron2/options" |
Jiri Simsa | 519c507 | 2014-09-17 21:37:57 -0700 | [diff] [blame] | 18 | "veyron.io/veyron/veyron2/security" |
Asim Shankar | 6888519 | 2014-11-26 12:48:35 -0800 | [diff] [blame] | 19 | "veyron.io/veyron/veyron2/services/security/access" |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 20 | old_verror "veyron.io/veyron/veyron2/verror" |
| 21 | verror "veyron.io/veyron/veyron2/verror2" |
Jiri Simsa | 519c507 | 2014-09-17 21:37:57 -0700 | [diff] [blame] | 22 | "veyron.io/veyron/veyron2/vlog" |
| 23 | "veyron.io/veyron/veyron2/vom" |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 24 | "veyron.io/veyron/veyron2/vom2" |
Jiri Simsa | 519c507 | 2014-09-17 21:37:57 -0700 | [diff] [blame] | 25 | "veyron.io/veyron/veyron2/vtrace" |
Cosmos Nicolaou | f889c73 | 2014-10-16 20:46:54 -0700 | [diff] [blame] | 26 | |
Cosmos Nicolaou | f889c73 | 2014-10-16 20:46:54 -0700 | [diff] [blame] | 27 | "veyron.io/veyron/veyron/lib/netstate" |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 28 | "veyron.io/veyron/veyron/lib/stats" |
| 29 | "veyron.io/veyron/veyron/runtimes/google/ipc/stream/vc" |
Cosmos Nicolaou | f889c73 | 2014-10-16 20:46:54 -0700 | [diff] [blame] | 30 | "veyron.io/veyron/veyron/runtimes/google/lib/publisher" |
| 31 | inaming "veyron.io/veyron/veyron/runtimes/google/naming" |
Cosmos Nicolaou | f889c73 | 2014-10-16 20:46:54 -0700 | [diff] [blame] | 32 | ivtrace "veyron.io/veyron/veyron/runtimes/google/vtrace" |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 33 | |
| 34 | // TODO(cnicolaou): finish verror -> verror2 transition, in particular |
| 35 | // for communicating from server to client. |
| 36 | // TODO(cnicolaou): remove the vom1 code now that vom2 is in place. |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | var ( |
Cosmos Nicolaou | 5a8a125 | 2014-12-01 14:14:25 -0800 | [diff] [blame] | 40 | // TODO(cnicolaou): this should be BadState in verror2. |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 41 | errServerStopped = old_verror.Abortedf("ipc: server is stopped") |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 44 | type server struct { |
| 45 | sync.Mutex |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 46 | ctx context.T // context used by the server to make internal RPCs. |
| 47 | streamMgr stream.Manager // stream manager to listen for new flows. |
| 48 | publisher publisher.Publisher // publisher to publish mounttable mounts. |
| 49 | listenerOpts []stream.ListenerOpt // listener opts passed to Listen. |
| 50 | listeners map[stream.Listener]struct{} // listeners created by Listen. |
| 51 | dhcpListeners map[*dhcpListener]struct{} // dhcpListeners created by Listen. |
| 52 | |
| 53 | disp ipc.Dispatcher // dispatcher to serve RPCs |
| 54 | dispReserved ipc.Dispatcher // dispatcher for reserved methods |
| 55 | active sync.WaitGroup // active goroutines we've spawned. |
| 56 | stopped bool // whether the server has been stopped. |
| 57 | stoppedChan chan struct{} // closed when the server has been stopped. |
| 58 | preferredProtocols []string // protocols to use when resolving proxy name to endpoint. |
Nicolas LaCasse | 55a10f3 | 2014-11-26 13:25:53 -0800 | [diff] [blame] | 59 | ns naming.Namespace |
| 60 | servesMountTable bool |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 61 | // TODO(cnicolaou): remove this when the publisher tracks published names |
| 62 | // and can return an appropriate error for RemoveName on a name that |
| 63 | // wasn't 'Added' for this server. |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 64 | names map[string]struct{} |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 65 | // TODO(cnicolaou): add roaming stats to ipcStats |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 66 | stats *ipcStats // stats for this server. |
| 67 | traceStore *ivtrace.Store // store for vtrace traces. |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Benjamin Prosnitz | fdfbf7b | 2014-10-08 09:47:21 -0700 | [diff] [blame] | 70 | var _ ipc.Server = (*server)(nil) |
| 71 | |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 72 | type dhcpListener struct { |
| 73 | sync.Mutex |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 74 | publisher *config.Publisher // publisher used to fork the stream |
| 75 | name string // name of the publisher stream |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 76 | eps []*inaming.Endpoint // endpoint returned after listening |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 77 | pubAddrs []ipc.Address // addresses to publish |
| 78 | pubPort string // port to use with the publish addresses |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 79 | ch chan config.Setting // channel to receive settings over |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Nicolas LaCasse | 55a10f3 | 2014-11-26 13:25:53 -0800 | [diff] [blame] | 82 | // This option is used to sort and filter the endpoints when resolving the |
| 83 | // proxy name from a mounttable. |
| 84 | type PreferredServerResolveProtocols []string |
| 85 | |
| 86 | func (PreferredServerResolveProtocols) IPCServerOpt() {} |
| 87 | |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 88 | func InternalNewServer(ctx context.T, streamMgr stream.Manager, ns naming.Namespace, store *ivtrace.Store, opts ...ipc.ServerOpt) (ipc.Server, error) { |
| 89 | ctx, _ = ivtrace.WithNewSpan(ctx, "NewServer") |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 90 | statsPrefix := naming.Join("ipc", "server", "routing-id", streamMgr.RoutingID().String()) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 91 | s := &server{ |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 92 | ctx: ctx, |
| 93 | streamMgr: streamMgr, |
| 94 | publisher: publisher.New(ctx, ns, publishPeriod), |
| 95 | listeners: make(map[stream.Listener]struct{}), |
| 96 | dhcpListeners: make(map[*dhcpListener]struct{}), |
| 97 | stoppedChan: make(chan struct{}), |
| 98 | ns: ns, |
| 99 | stats: newIPCStats(statsPrefix), |
| 100 | traceStore: store, |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 101 | } |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 102 | var ( |
| 103 | principal security.Principal |
| 104 | blessings security.Blessings |
| 105 | ) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 106 | for _, opt := range opts { |
Bogdan Caprita | 187269b | 2014-05-13 19:59:46 -0700 | [diff] [blame] | 107 | switch opt := opt.(type) { |
| 108 | case stream.ListenerOpt: |
| 109 | // Collect all ServerOpts that are also ListenerOpts. |
| 110 | s.listenerOpts = append(s.listenerOpts, opt) |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 111 | switch opt := opt.(type) { |
| 112 | case vc.LocalPrincipal: |
| 113 | principal = opt.Principal |
| 114 | case options.ServerBlessings: |
| 115 | blessings = opt.Blessings |
| 116 | } |
Asim Shankar | cc04421 | 2014-10-15 23:25:26 -0700 | [diff] [blame] | 117 | case options.ServesMountTable: |
Cosmos Nicolaou | e6e87f1 | 2014-06-03 14:29:10 -0700 | [diff] [blame] | 118 | s.servesMountTable = bool(opt) |
Cosmos Nicolaou | 8246a8b | 2014-11-01 09:32:36 -0700 | [diff] [blame] | 119 | case options.ReservedNameDispatcher: |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 120 | s.dispReserved = opt.Dispatcher |
Nicolas LaCasse | 55a10f3 | 2014-11-26 13:25:53 -0800 | [diff] [blame] | 121 | case PreferredServerResolveProtocols: |
| 122 | s.preferredProtocols = []string(opt) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
Bogdan Caprita | e737631 | 2014-11-10 13:13:17 -0800 | [diff] [blame] | 125 | blessingsStatsName := naming.Join(statsPrefix, "security", "blessings") |
| 126 | if blessings != nil { |
| 127 | // TODO(caprita): revist printing the blessings with %s, and |
| 128 | // instead expose them as a list. |
| 129 | stats.NewString(blessingsStatsName).Set(fmt.Sprintf("%s", blessings)) |
| 130 | } else if principal != nil { // principal should have been passed in, but just in case. |
| 131 | stats.NewStringFunc(blessingsStatsName, func() string { |
| 132 | return fmt.Sprintf("%s (default)", principal.BlessingStore().Default()) |
| 133 | }) |
| 134 | } |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 135 | return s, nil |
| 136 | } |
| 137 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 138 | func (s *server) Published() ([]string, error) { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 139 | defer vlog.LogCall()() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 140 | s.Lock() |
| 141 | defer s.Unlock() |
| 142 | if s.stopped { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 143 | return nil, s.newBadState("ipc.Server.Stop already called") |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 144 | } |
| 145 | return s.publisher.Published(), nil |
| 146 | } |
| 147 | |
Robin Thellend | 92b65a4 | 2014-12-17 14:30:16 -0800 | [diff] [blame] | 148 | // resolveToEndpoint resolves an object name or address to an endpoint. |
| 149 | func (s *server) resolveToEndpoint(address string) (string, error) { |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 150 | var names []string |
| 151 | if s.ns != nil { |
Ryan Brown | 6153c6c | 2014-12-11 13:10:09 -0800 | [diff] [blame] | 152 | var entry *naming.MountEntry |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 153 | var err error |
Ryan Brown | 6153c6c | 2014-12-11 13:10:09 -0800 | [diff] [blame] | 154 | if entry, err = s.ns.ResolveX(s.ctx, address); err != nil { |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 155 | return "", err |
| 156 | } |
Ryan Brown | 6153c6c | 2014-12-11 13:10:09 -0800 | [diff] [blame] | 157 | names = naming.ToStringSlice(entry) |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 158 | } else { |
| 159 | names = append(names, address) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 160 | } |
Nicolas LaCasse | 55a10f3 | 2014-11-26 13:25:53 -0800 | [diff] [blame] | 161 | // An empty set of protocols means all protocols... |
| 162 | ordered, err := filterAndOrderServers(names, s.preferredProtocols) |
| 163 | if err != nil { |
| 164 | return "", err |
| 165 | } |
| 166 | for _, n := range ordered { |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 167 | address, suffix := naming.SplitAddressName(n) |
David Why Use Two When One Will Do Presotto | adf0ca1 | 2014-11-13 10:49:01 -0800 | [diff] [blame] | 168 | if suffix != "" { |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 169 | continue |
| 170 | } |
| 171 | if _, err := inaming.NewEndpoint(address); err == nil { |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 172 | return address, nil |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 173 | } |
| 174 | } |
Asim Shankar | dee311d | 2014-08-01 17:41:31 -0700 | [diff] [blame] | 175 | return "", fmt.Errorf("unable to resolve %q to an endpoint", address) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 178 | func addrFromIP(ip net.IP) ipc.Address { |
| 179 | return &netstate.AddrIfc{ |
| 180 | Addr: &net.IPAddr{IP: ip}, |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 181 | } |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 184 | /* |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 185 | // getIPRoamingAddrs finds an appropriate set of addresss to publish |
| 186 | // externally and also determines if it's sensible to allow roaming. |
| 187 | // It returns the host address of the first suitable address that |
| 188 | // can be used and the port number that can be used with all addresses. |
| 189 | // The host is required to allow the caller to construct an endpoint |
| 190 | // that can be returned to the caller of Listen. |
| 191 | func (s *server) getIPRoamingAddrs(chooser ipc.AddressChooser, iep *inaming.Endpoint) (addresses []ipc.Address, host string, port string, roaming bool, err error) { |
| 192 | host, port, err = net.SplitHostPort(iep.Address) |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 193 | if err != nil { |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 194 | return nil, "", "", false, err |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 195 | } |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 196 | ip := net.ParseIP(host) |
| 197 | if ip == nil { |
| 198 | return nil, "", "", false, fmt.Errorf("failed to parse %q as an IP host", host) |
| 199 | } |
| 200 | if ip.IsUnspecified() && chooser != nil { |
| 201 | // Need to find a usable IP address since the call to listen |
| 202 | // didn't specify one. |
| 203 | if addrs, err := netstate.GetAccessibleIPs(); err == nil { |
| 204 | if a, err := chooser(iep.Protocol, addrs); err == nil && len(a) > 0 { |
| 205 | phost := a[0].Address().String() |
| 206 | iep.Address = net.JoinHostPort(phost, port) |
| 207 | return a, phost, port, true, nil |
| 208 | } |
| 209 | } |
| 210 | return []ipc.Address{addrFromIP(ip)}, host, port, true, nil |
| 211 | } |
| 212 | // Listen used a fixed IP address, which we take to mean that |
| 213 | // roaming is not desired. |
| 214 | return []ipc.Address{addrFromIP(ip)}, host, port, false, nil |
| 215 | } |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 216 | */ |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 217 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 218 | // getPossbileAddrs returns an appropriate set of addresses that could be used |
| 219 | // to contact the supplied protocol, host, port parameters using the supplied |
| 220 | // chooser function. It returns an indication of whether the supplied address |
| 221 | // was fully specified or not, returning false if the address was fully |
| 222 | // specified, and true if it was not. |
| 223 | func getPossibleAddrs(protocol, host, port string, chooser ipc.AddressChooser) ([]ipc.Address, bool, error) { |
| 224 | ip := net.ParseIP(host) |
| 225 | if ip == nil { |
| 226 | return nil, false, fmt.Errorf("failed to parse %q as an IP host", host) |
| 227 | } |
| 228 | if ip.IsUnspecified() { |
| 229 | if chooser != nil { |
| 230 | // Need to find a usable IP address since the call to listen |
| 231 | // didn't specify one. |
| 232 | if addrs, err := netstate.GetAccessibleIPs(); err == nil { |
Cosmos Nicolaou | d70e1fc | 2014-12-16 14:20:39 -0800 | [diff] [blame] | 233 | a, err := chooser(protocol, addrs) |
| 234 | if err == nil && len(a) > 0 { |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 235 | return a, true, nil |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | // We don't have a chooser, so we just return the address the |
| 240 | // underlying system has chosen. |
| 241 | return []ipc.Address{addrFromIP(ip)}, true, nil |
| 242 | } |
| 243 | return []ipc.Address{addrFromIP(ip)}, false, nil |
| 244 | } |
| 245 | |
| 246 | // createEndpoints creates appropriate inaming.Endpoint instances for |
| 247 | // all of the externally accessible networrk addresses that can be used |
| 248 | // to reach this server. |
| 249 | func (s *server) createEndpoints(lep naming.Endpoint, chooser ipc.AddressChooser) ([]*inaming.Endpoint, bool, error) { |
| 250 | iep, ok := lep.(*inaming.Endpoint) |
| 251 | if !ok { |
| 252 | return nil, false, fmt.Errorf("internal type conversion error for %T", lep) |
| 253 | } |
| 254 | if !strings.HasPrefix(iep.Protocol, "tcp") && |
| 255 | !strings.HasPrefix(iep.Protocol, "ws") { |
| 256 | // If not tcp or ws, just return the endpoint we were given. |
| 257 | return []*inaming.Endpoint{iep}, false, nil |
| 258 | } |
| 259 | |
| 260 | host, port, err := net.SplitHostPort(iep.Address) |
| 261 | if err != nil { |
| 262 | return nil, false, err |
| 263 | } |
Cosmos Nicolaou | d70e1fc | 2014-12-16 14:20:39 -0800 | [diff] [blame] | 264 | addrs, unspecified, err := getPossibleAddrs(iep.Protocol, host, port, chooser) |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 265 | if err != nil { |
| 266 | return nil, false, err |
| 267 | } |
| 268 | ieps := make([]*inaming.Endpoint, 0, len(addrs)) |
| 269 | for _, addr := range addrs { |
| 270 | n, err := inaming.NewEndpoint(lep.String()) |
| 271 | if err != nil { |
| 272 | return nil, false, err |
| 273 | } |
| 274 | n.IsMountTable = s.servesMountTable |
| 275 | //n.Protocol = addr.Address().Network() |
| 276 | n.Address = net.JoinHostPort(addr.Address().String(), port) |
| 277 | ieps = append(ieps, n) |
| 278 | } |
| 279 | return ieps, unspecified, nil |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | // configureEPAndRoaming configures the endpoint by filling in its Address |
| 284 | // portion with the appropriately selected network address, it also |
| 285 | // returns an indication of whether this endpoint is appropriate for |
| 286 | // roaming and the set of addresses that should be published. |
| 287 | func (s *server) configureEPAndRoaming(spec ipc.ListenSpec, ep naming.Endpoint) (bool, []ipc.Address, *inaming.Endpoint, error) { |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 288 | iep, ok := ep.(*inaming.Endpoint) |
| 289 | if !ok { |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 290 | return false, nil, nil, fmt.Errorf("internal type conversion error for %T", ep) |
Cosmos Nicolaou | aef5e37 | 2014-11-07 16:59:59 -0800 | [diff] [blame] | 291 | } |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 292 | if !strings.HasPrefix(spec.Addrs[0].Protocol, "tcp") && |
| 293 | !strings.HasPrefix(spec.Addrs[0].Protocol, "ws") { |
| 294 | return false, nil, iep, nil |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 295 | } |
| 296 | pubAddrs, pubHost, pubPort, roaming, err := s.getIPRoamingAddrs(spec.AddressChooser, iep) |
| 297 | if err != nil { |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 298 | return false, nil, iep, err |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 299 | } |
| 300 | iep.Address = net.JoinHostPort(pubHost, pubPort) |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 301 | return roaming, pubAddrs, iep, nil |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 302 | } |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 303 | */ |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 304 | |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 305 | type listenError struct { |
| 306 | err verror.E |
| 307 | errors map[struct{ Protocol, Address string }]error |
| 308 | } |
| 309 | |
| 310 | func newError() *listenError { |
| 311 | return &listenError{errors: make(map[struct{ Protocol, Address string }]error)} |
| 312 | } |
| 313 | |
| 314 | func ErrorDetails(le *listenError) map[struct{ Protocol, Address string }]error { |
| 315 | return le.errors |
| 316 | } |
| 317 | |
| 318 | // Implements error |
| 319 | func (le *listenError) Error() string { |
| 320 | s := le.err.Error() |
| 321 | for k, v := range le.errors { |
| 322 | s += fmt.Sprintf("(%s,%s:%s) ", k.Protocol, k.Address, v) |
| 323 | } |
| 324 | return strings.TrimRight(s, " ") |
| 325 | } |
| 326 | |
| 327 | func (le *listenError) ErrorID() old_verror.ID { |
| 328 | return le.err.ErrorID() |
| 329 | } |
| 330 | |
| 331 | func (le *listenError) Action() verror.ActionCode { |
| 332 | return le.err.Action() |
| 333 | } |
| 334 | |
| 335 | func (le *listenError) Params() []interface{} { |
| 336 | return le.err.Params() |
| 337 | } |
| 338 | |
| 339 | func (le *listenError) HasMessage() bool { |
| 340 | return le.err.HasMessage() |
| 341 | } |
| 342 | |
| 343 | func (le *listenError) Stack() verror.PCs { |
| 344 | return le.err.Stack() |
| 345 | } |
| 346 | |
| 347 | func (s *server) newBadState(m string) *listenError { |
| 348 | return &listenError{err: verror.Make(verror.BadState, s.ctx, m)} |
| 349 | } |
| 350 | |
| 351 | func (s *server) newBadArg(m string) *listenError { |
| 352 | return &listenError{err: verror.Make(verror.BadArg, s.ctx, m)} |
| 353 | } |
| 354 | |
| 355 | func (s *server) Listen(listenSpec ipc.ListenSpec) ([]naming.Endpoint, error) { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 356 | defer vlog.LogCall()() |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 357 | s.Lock() |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 358 | |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 359 | // Shortcut if the server is stopped, to avoid needlessly creating a |
| 360 | // listener. |
| 361 | if s.stopped { |
| 362 | s.Unlock() |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 363 | return nil, s.newBadState("ipc.Server.Stop already called") |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 364 | } |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 365 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 366 | useProxy := len(listenSpec.Proxy) > 0 |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 367 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 368 | // Start the proxy as early as possible. |
| 369 | if useProxy { |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 370 | // We have a goroutine for listening on proxy connections. |
Cosmos Nicolaou | eef1fab | 2014-11-11 18:23:41 -0800 | [diff] [blame] | 371 | s.active.Add(1) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 372 | go func() { |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 373 | s.proxyListenLoop(listenSpec.Proxy) |
| 374 | s.active.Done() |
| 375 | }() |
| 376 | } |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 377 | s.Unlock() |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 378 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 379 | var ieps []*inaming.Endpoint |
| 380 | |
| 381 | type lnInfo struct { |
| 382 | ln stream.Listener |
| 383 | ep naming.Endpoint |
| 384 | } |
| 385 | linfo := []lnInfo{} |
| 386 | closeAll := func(lni []lnInfo) { |
| 387 | for _, li := range lni { |
| 388 | li.ln.Close() |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | roaming := false |
| 393 | for _, addr := range listenSpec.Addrs { |
| 394 | if len(addr.Address) > 0 { |
| 395 | // Listen if we have a local address to listen on. Some situations |
| 396 | // just need a proxy (e.g. a browser extension). |
| 397 | tmpln, lep, err := s.streamMgr.Listen(addr.Protocol, addr.Address, s.listenerOpts...) |
| 398 | if err != nil { |
| 399 | closeAll(linfo) |
| 400 | vlog.Errorf("ipc: Listen on %s failed: %s", addr, err) |
| 401 | return nil, err |
| 402 | } |
| 403 | linfo = append(linfo, lnInfo{tmpln, lep}) |
| 404 | tmpieps, tmpRoaming, err := s.createEndpoints(lep, listenSpec.AddressChooser) |
| 405 | if err != nil { |
| 406 | closeAll(linfo) |
| 407 | return nil, err |
| 408 | } |
| 409 | ieps = append(ieps, tmpieps...) |
| 410 | if tmpRoaming { |
| 411 | roaming = true |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // TODO(cnicolaou): write a test for all of these error cases. |
| 417 | if len(ieps) == 0 { |
| 418 | if useProxy { |
| 419 | return nil, nil |
| 420 | } |
| 421 | // no proxy. |
| 422 | if len(listenSpec.Addrs) > 0 { |
| 423 | return nil, fmt.Errorf("no endpoints") |
| 424 | } |
| 425 | return nil, fmt.Errorf("no proxy and no addresses requested") |
| 426 | } |
| 427 | |
| 428 | // TODO(cnicolaou): return all of the eps and their errors.... |
| 429 | s.Lock() |
| 430 | defer s.Unlock() |
| 431 | if s.stopped { |
| 432 | closeAll(linfo) |
| 433 | return nil, errServerStopped |
| 434 | } |
| 435 | |
| 436 | if roaming && listenSpec.StreamPublisher != nil { |
| 437 | // TODO(cnicolaou): renable roaming in a followup CL. |
| 438 | /* |
| 439 | var dhcpl *dhcpListener |
| 440 | streamName := listenSpec.StreamName |
| 441 | ch := make(chan config.Setting) |
| 442 | if _, err := publisher.ForkStream(streamName, ch); err != nil { |
| 443 | return ieps[0], fmt.Errorf("failed to fork stream %q: %s", streamName, err) |
| 444 | } |
| 445 | dhcpl = &dhcpListener{eps: ieps, pubAddrs: pubAddrs, ch: ch, name: streamName, publisher: publisher}, iep, nil |
| 446 | // We have a goroutine to listen for dhcp changes. |
| 447 | s.active.Add(1) |
| 448 | go func() { |
| 449 | s.dhcpLoop(dhcpl) |
| 450 | s.active.Done() |
| 451 | }() |
| 452 | s.dhcpListeners[dhcpl] = struct{}{} |
| 453 | */ |
| 454 | } |
| 455 | |
| 456 | for _, li := range linfo { |
| 457 | s.listeners[li.ln] = struct{}{} |
| 458 | // We have a goroutine per listener to accept new flows. |
| 459 | // Each flow is served from its own goroutine. |
| 460 | s.active.Add(1) |
| 461 | go func(ln stream.Listener, ep naming.Endpoint) { |
| 462 | s.listenLoop(ln, ep) |
| 463 | s.active.Done() |
| 464 | }(li.ln, li.ep) |
| 465 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 466 | eps := make([]naming.Endpoint, len(ieps)) |
| 467 | for i, iep := range ieps { |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 468 | s.publisher.AddServer(naming.JoinAddressName(iep.String(), ""), s.servesMountTable) |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 469 | eps[i] = iep |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 470 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 471 | return eps, nil |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 474 | func (s *server) reconnectAndPublishProxy(proxy string) (*inaming.Endpoint, stream.Listener, error) { |
Robin Thellend | 92b65a4 | 2014-12-17 14:30:16 -0800 | [diff] [blame] | 475 | resolved, err := s.resolveToEndpoint(proxy) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 476 | if err != nil { |
| 477 | return nil, nil, fmt.Errorf("Failed to resolve proxy %q (%v)", proxy, err) |
| 478 | } |
| 479 | ln, ep, err := s.streamMgr.Listen(inaming.Network, resolved, s.listenerOpts...) |
| 480 | if err != nil { |
| 481 | return nil, nil, fmt.Errorf("failed to listen on %q: %s", resolved, err) |
| 482 | } |
| 483 | iep, ok := ep.(*inaming.Endpoint) |
| 484 | if !ok { |
| 485 | ln.Close() |
| 486 | return nil, nil, fmt.Errorf("internal type conversion error for %T", ep) |
| 487 | } |
| 488 | s.Lock() |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 489 | s.listeners[ln] = struct{}{} |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 490 | s.Unlock() |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 491 | s.publisher.AddServer(naming.JoinAddressName(iep.String(), ""), s.servesMountTable) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 492 | return iep, ln, nil |
| 493 | } |
| 494 | |
| 495 | func (s *server) proxyListenLoop(proxy string) { |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 496 | const ( |
| 497 | min = 5 * time.Millisecond |
| 498 | max = 5 * time.Minute |
| 499 | ) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 500 | |
| 501 | iep, ln, err := s.reconnectAndPublishProxy(proxy) |
| 502 | if err != nil { |
| 503 | vlog.VI(1).Infof("Failed to connect to proxy: %s", err) |
| 504 | } |
| 505 | // the initial connection maybe have failed, but we enter the retry |
| 506 | // loop anyway so that we will continue to try and connect to the |
| 507 | // proxy. |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 508 | s.Lock() |
| 509 | if s.stopped { |
| 510 | s.Unlock() |
| 511 | return |
| 512 | } |
| 513 | s.Unlock() |
| 514 | |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 515 | for { |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 516 | if ln != nil && iep != nil { |
| 517 | s.listenLoop(ln, iep) |
| 518 | // The listener is done, so: |
| 519 | // (1) Unpublish its name |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 520 | s.publisher.RemoveServer(naming.JoinAddressName(iep.String(), "")) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | s.Lock() |
| 524 | if s.stopped { |
| 525 | s.Unlock() |
| 526 | return |
| 527 | } |
| 528 | s.Unlock() |
| 529 | |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 530 | // (2) Reconnect to the proxy unless the server has been stopped |
| 531 | backoff := min |
| 532 | ln = nil |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 533 | for { |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 534 | select { |
| 535 | case <-time.After(backoff): |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 536 | if backoff = backoff * 2; backoff > max { |
| 537 | backoff = max |
| 538 | } |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 539 | case <-s.stoppedChan: |
| 540 | return |
| 541 | } |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 542 | // (3) reconnect, publish new address |
| 543 | if iep, ln, err = s.reconnectAndPublishProxy(proxy); err != nil { |
| 544 | vlog.VI(1).Infof("Failed to reconnect to proxy %q: %s", proxy, err) |
| 545 | } else { |
| 546 | vlog.VI(1).Infof("Reconnected to proxy %q, %s", proxy, iep) |
| 547 | break |
| 548 | } |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 549 | } |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | func (s *server) listenLoop(ln stream.Listener, ep naming.Endpoint) { |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 554 | defer vlog.VI(1).Infof("ipc: Stopped listening on %s", ep) |
Cosmos Nicolaou | eef1fab | 2014-11-11 18:23:41 -0800 | [diff] [blame] | 555 | var calls sync.WaitGroup |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 556 | defer func() { |
Cosmos Nicolaou | eef1fab | 2014-11-11 18:23:41 -0800 | [diff] [blame] | 557 | calls.Wait() |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 558 | s.Lock() |
| 559 | delete(s.listeners, ln) |
| 560 | s.Unlock() |
| 561 | }() |
| 562 | for { |
| 563 | flow, err := ln.Accept() |
| 564 | if err != nil { |
Todd Wang | 03fee96 | 2014-12-08 19:33:10 -0800 | [diff] [blame] | 565 | vlog.VI(10).Infof("ipc: Accept on %v failed: %v", ep, err) |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 566 | return |
| 567 | } |
Cosmos Nicolaou | eef1fab | 2014-11-11 18:23:41 -0800 | [diff] [blame] | 568 | calls.Add(1) |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 569 | go func(flow stream.Flow) { |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 570 | defer calls.Done() |
| 571 | fs, err := newFlowServer(flow, s) |
| 572 | if err != nil { |
Todd Wang | 03fee96 | 2014-12-08 19:33:10 -0800 | [diff] [blame] | 573 | vlog.Errorf("newFlowServer on %v failed: %v", ep, err) |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 574 | return |
| 575 | } |
| 576 | if err := fs.serve(); err != nil { |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 577 | // TODO(caprita): Logging errors here is too spammy. For example, "not |
| 578 | // authorized" errors shouldn't be logged as server errors. |
Cosmos Nicolaou | 1534b3f | 2014-12-10 15:30:00 -0800 | [diff] [blame] | 579 | if err != io.EOF { |
| 580 | vlog.Errorf("Flow serve on %v failed: %v", ep, err) |
| 581 | } |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 582 | } |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 583 | }(flow) |
| 584 | } |
| 585 | } |
| 586 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 587 | /* |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 588 | func (s *server) applyChange(dhcpl *dhcpListener, addrs []net.Addr, fn func(string)) { |
| 589 | dhcpl.Lock() |
| 590 | defer dhcpl.Unlock() |
| 591 | for _, a := range addrs { |
| 592 | if ip := netstate.AsIP(a); ip != nil { |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 593 | dhcpl.ep.Address = net.JoinHostPort(ip.String(), dhcpl.pubPort) |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 594 | fn(dhcpl.ep.String()) |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | func (s *server) dhcpLoop(dhcpl *dhcpListener) { |
| 600 | defer vlog.VI(1).Infof("ipc: Stopped listen for dhcp changes on %v", dhcpl.ep) |
| 601 | vlog.VI(2).Infof("ipc: dhcp loop") |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 602 | |
| 603 | ep := *dhcpl.ep |
| 604 | // Publish all of the addresses |
| 605 | for _, pubAddr := range dhcpl.pubAddrs { |
| 606 | ep.Address = net.JoinHostPort(pubAddr.Address().String(), dhcpl.pubPort) |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 607 | s.publisher.AddServer(naming.JoinAddressName(ep.String(), ""), s.servesMountTable) |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 610 | for setting := range dhcpl.ch { |
| 611 | if setting == nil { |
| 612 | return |
| 613 | } |
| 614 | switch v := setting.Value().(type) { |
| 615 | case bool: |
| 616 | return |
| 617 | case []net.Addr: |
| 618 | s.Lock() |
| 619 | if s.stopped { |
| 620 | s.Unlock() |
| 621 | return |
| 622 | } |
| 623 | publisher := s.publisher |
| 624 | s.Unlock() |
| 625 | switch setting.Name() { |
| 626 | case ipc.NewAddrsSetting: |
| 627 | vlog.Infof("Added some addresses: %q", v) |
David Why Use Two When One Will Do Presotto | 3da1c79 | 2014-10-03 11:15:53 -0700 | [diff] [blame] | 628 | s.applyChange(dhcpl, v, func(name string) { publisher.AddServer(name, s.servesMountTable) }) |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 629 | case ipc.RmAddrsSetting: |
| 630 | vlog.Infof("Removed some addresses: %q", v) |
| 631 | s.applyChange(dhcpl, v, publisher.RemoveServer) |
| 632 | } |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | } |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 636 | */ |
Cosmos Nicolaou | ef323db | 2014-09-07 22:13:28 -0700 | [diff] [blame] | 637 | |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 638 | func (s *server) Serve(name string, obj interface{}, authorizer security.Authorizer) error { |
Cosmos Nicolaou | 61c96c7 | 2014-11-03 11:57:56 -0800 | [diff] [blame] | 639 | if obj == nil { |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 640 | // The ReflectInvoker inside the LeafDispatcher will panic |
| 641 | // if called for a nil value. |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 642 | return s.newBadArg("nil object") |
Cosmos Nicolaou | 61c96c7 | 2014-11-03 11:57:56 -0800 | [diff] [blame] | 643 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 644 | return s.ServeDispatcher(name, ipc.LeafDispatcher(obj, authorizer)) |
Cosmos Nicolaou | 61c96c7 | 2014-11-03 11:57:56 -0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | func (s *server) ServeDispatcher(name string, disp ipc.Dispatcher) error { |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 648 | s.Lock() |
| 649 | defer s.Unlock() |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 650 | ivtrace.FromContext(s.ctx).Annotate("Serving under name: " + name) |
| 651 | |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 652 | if s.stopped { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 653 | return s.newBadState("ipc.Server.Stop already called") |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 654 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 655 | if disp == nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 656 | return s.newBadArg("nil dispatcher") |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 657 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 658 | if s.disp != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 659 | return s.newBadState("ipc.Server.Serve/ServeDispatcher already called") |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 660 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 661 | s.disp = disp |
| 662 | s.names = make(map[string]struct{}) |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 663 | if len(name) > 0 { |
| 664 | s.publisher.AddName(name) |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 665 | s.names[name] = struct{}{} |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 666 | } |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 667 | return nil |
| 668 | } |
| 669 | |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 670 | func (s *server) AddName(name string) error { |
| 671 | s.Lock() |
| 672 | defer s.Unlock() |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 673 | ivtrace.FromContext(s.ctx).Annotate("Serving under name: " + name) |
Ali Ghassemi | 3c6db7b | 2014-11-10 17:20:26 -0800 | [diff] [blame] | 674 | if len(name) == 0 { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 675 | return s.newBadArg("name is empty") |
Ali Ghassemi | 3c6db7b | 2014-11-10 17:20:26 -0800 | [diff] [blame] | 676 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 677 | if s.stopped { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 678 | return s.newBadState("ipc.Server.Stop already called") |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 679 | } |
Ali Ghassemi | 3c6db7b | 2014-11-10 17:20:26 -0800 | [diff] [blame] | 680 | if s.disp == nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 681 | return s.newBadState("adding a name before calling Serve or ServeDispatcher is not allowed") |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 682 | } |
| 683 | s.publisher.AddName(name) |
| 684 | // TODO(cnicolaou): remove this map when the publisher's RemoveName |
| 685 | // method returns an error. |
| 686 | s.names[name] = struct{}{} |
| 687 | return nil |
| 688 | } |
| 689 | |
| 690 | func (s *server) RemoveName(name string) error { |
| 691 | s.Lock() |
| 692 | defer s.Unlock() |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 693 | ivtrace.FromContext(s.ctx).Annotate("Removed name: " + name) |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 694 | if s.stopped { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 695 | return s.newBadState("ipc.Server.Stop already called") |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 696 | } |
Ali Ghassemi | 3c6db7b | 2014-11-10 17:20:26 -0800 | [diff] [blame] | 697 | if s.disp == nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 698 | return s.newBadState("removing name before calling Serve or ServeDispatcher is not allowed") |
Ali Ghassemi | 3c6db7b | 2014-11-10 17:20:26 -0800 | [diff] [blame] | 699 | } |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 700 | if _, present := s.names[name]; !present { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 701 | return s.newBadArg(fmt.Sprintf("%q has not been previously used for this server", name)) |
Cosmos Nicolaou | 92dba58 | 2014-11-05 17:24:10 -0800 | [diff] [blame] | 702 | } |
| 703 | s.publisher.RemoveName(name) |
| 704 | delete(s.names, name) |
| 705 | return nil |
| 706 | } |
| 707 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 708 | func (s *server) Stop() error { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 709 | defer vlog.LogCall()() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 710 | s.Lock() |
| 711 | if s.stopped { |
| 712 | s.Unlock() |
| 713 | return nil |
| 714 | } |
| 715 | s.stopped = true |
Asim Shankar | 0ea02ab | 2014-06-09 11:39:24 -0700 | [diff] [blame] | 716 | close(s.stoppedChan) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 717 | s.Unlock() |
| 718 | |
Robin Thellend | df42823 | 2014-10-06 12:50:44 -0700 | [diff] [blame] | 719 | // Delete the stats object. |
| 720 | s.stats.stop() |
| 721 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 722 | // Note, It's safe to Stop/WaitForStop on the publisher outside of the |
| 723 | // server lock, since publisher is safe for concurrent access. |
| 724 | |
| 725 | // Stop the publisher, which triggers unmounting of published names. |
| 726 | s.publisher.Stop() |
| 727 | // Wait for the publisher to be done unmounting before we can proceed to |
| 728 | // close the listeners (to minimize the number of mounted names pointing |
| 729 | // to endpoint that are no longer serving). |
| 730 | // |
| 731 | // TODO(caprita): See if make sense to fail fast on rejecting |
| 732 | // connections once listeners are closed, and parallelize the publisher |
| 733 | // and listener shutdown. |
| 734 | s.publisher.WaitForStop() |
| 735 | |
| 736 | s.Lock() |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 737 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 738 | // Close all listeners. No new flows will be accepted, while in-flight |
| 739 | // flows will continue until they terminate naturally. |
| 740 | nListeners := len(s.listeners) |
| 741 | errCh := make(chan error, nListeners) |
Cosmos Nicolaou | bc74314 | 2014-10-06 21:27:18 -0700 | [diff] [blame] | 742 | |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 743 | for ln, _ := range s.listeners { |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 744 | go func(ln stream.Listener) { |
| 745 | errCh <- ln.Close() |
| 746 | }(ln) |
Cosmos Nicolaou | ae8dd21 | 2014-12-13 23:43:08 -0800 | [diff] [blame] | 747 | } |
| 748 | for dhcpl, _ := range s.dhcpListeners { |
| 749 | dhcpl.Lock() |
| 750 | dhcpl.publisher.CloseFork(dhcpl.name, dhcpl.ch) |
| 751 | dhcpl.ch <- config.NewBool("EOF", "stop", true) |
| 752 | dhcpl.Unlock() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 753 | } |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 754 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 755 | s.Unlock() |
| 756 | var firstErr error |
| 757 | for i := 0; i < nListeners; i++ { |
| 758 | if err := <-errCh; err != nil && firstErr == nil { |
| 759 | firstErr = err |
| 760 | } |
| 761 | } |
| 762 | // At this point, we are guaranteed that no new requests are going to be |
| 763 | // accepted. |
| 764 | |
| 765 | // Wait for the publisher and active listener + flows to finish. |
| 766 | s.active.Wait() |
Cosmos Nicolaou | 9388ae4 | 2014-11-10 10:57:15 -0800 | [diff] [blame] | 767 | |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 768 | s.Lock() |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 769 | defer s.Unlock() |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 770 | s.disp = nil |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 771 | if firstErr != nil { |
| 772 | return verror.Make(verror.Internal, s.ctx, firstErr) |
| 773 | } |
| 774 | return nil |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 777 | // TODO(toddw): Remove these interfaces after the vom2 transition. |
| 778 | type vomEncoder interface { |
| 779 | Encode(v interface{}) error |
| 780 | } |
| 781 | |
| 782 | type vomDecoder interface { |
| 783 | Decode(v interface{}) error |
| 784 | } |
| 785 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 786 | // flowServer implements the RPC server-side protocol for a single RPC, over a |
| 787 | // flow that's already connected to the client. |
| 788 | type flowServer struct { |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 789 | context.T |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 790 | server *server // ipc.Server that this flow server belongs to |
| 791 | disp ipc.Dispatcher // ipc.Dispatcher that will serve RPCs on this flow |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 792 | dec vomDecoder // to decode requests and args from the client |
| 793 | enc vomEncoder // to encode responses and results to the client |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 794 | flow stream.Flow // underlying flow |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 795 | |
Asim Shankar | 220a015 | 2014-10-30 21:21:09 -0700 | [diff] [blame] | 796 | // Fields filled in during the server invocation. |
| 797 | blessings security.Blessings |
| 798 | method, suffix string |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 799 | tags []interface{} |
Asim Shankar | 220a015 | 2014-10-30 21:21:09 -0700 | [diff] [blame] | 800 | discharges map[string]security.Discharge |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 801 | starttime time.Time |
Asim Shankar | 220a015 | 2014-10-30 21:21:09 -0700 | [diff] [blame] | 802 | endStreamArgs bool // are the stream args at EOF? |
| 803 | allowDebug bool // true if the caller is permitted to view debug information. |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Benjamin Prosnitz | fdfbf7b | 2014-10-08 09:47:21 -0700 | [diff] [blame] | 806 | var _ ipc.Stream = (*flowServer)(nil) |
| 807 | |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 808 | func newFlowServer(flow stream.Flow, server *server) (*flowServer, error) { |
Cosmos Nicolaou | dcba93d | 2014-07-30 11:09:26 -0700 | [diff] [blame] | 809 | server.Lock() |
| 810 | disp := server.disp |
| 811 | server.Unlock() |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 812 | |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 813 | fs := &flowServer{ |
| 814 | T: server.ctx, |
| 815 | server: server, |
| 816 | disp: disp, |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 817 | flow: flow, |
| 818 | discharges: make(map[string]security.Discharge), |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 819 | } |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 820 | if vom2.IsEnabled() { |
| 821 | var err error |
| 822 | if fs.dec, err = vom2.NewDecoder(flow); err != nil { |
| 823 | flow.Close() |
| 824 | return nil, err |
| 825 | } |
| 826 | if fs.enc, err = vom2.NewBinaryEncoder(flow); err != nil { |
| 827 | flow.Close() |
| 828 | return nil, err |
| 829 | } |
| 830 | } else { |
| 831 | fs.dec = vom.NewDecoder(flow) |
| 832 | fs.enc = vom.NewEncoder(flow) |
| 833 | } |
| 834 | return fs, nil |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | // Vom does not encode untyped nils. |
| 838 | // Consequently, the ipc system does not allow nil results with an interface |
| 839 | // type from server methods. The one exception being errors. |
| 840 | // |
| 841 | // For now, the following hacky assumptions are made, which will be revisited when |
| 842 | // a decision is made on how untyped nils should be encoded/decoded in |
| 843 | // vom/vom2: |
| 844 | // |
| 845 | // - Server methods return 0 or more results |
| 846 | // - Any values returned by the server that have an interface type are either |
| 847 | // non-nil or of type error. |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 848 | func vomErrorHack(res interface{}) vom.Value { |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 849 | v := vom.ValueOf(res) |
| 850 | if !v.IsValid() { |
| 851 | // Untyped nils are assumed to be nil-errors. |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 852 | var boxed old_verror.E |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 853 | return vom.ValueOf(&boxed).Elem() |
| 854 | } |
| 855 | if err, iserr := res.(error); iserr { |
| 856 | // Convert errors to verror since errors are often not |
| 857 | // serializable via vom/gob (errors.New and fmt.Errorf return a |
| 858 | // type with no exported fields). |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 859 | return vom.ValueOf(old_verror.Convert(err)) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 860 | } |
| 861 | return v |
| 862 | } |
| 863 | |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 864 | // TODO(toddw): Remove this function and encodeValueHack after the vom2 transition. |
| 865 | func vom2ErrorHack(res interface{}) interface{} { |
| 866 | if err, ok := res.(error); ok { |
| 867 | return &err |
| 868 | } |
| 869 | return res |
| 870 | } |
| 871 | |
| 872 | // TODO(toddw): Remove this function and vom2ErrorHack after the vom2 transition. |
| 873 | func (fs *flowServer) encodeValueHack(res interface{}) error { |
| 874 | if vom2.IsEnabled() { |
| 875 | return fs.enc.Encode(vom2ErrorHack(res)) |
| 876 | } |
| 877 | return fs.enc.(*vom.Encoder).EncodeValue(vomErrorHack(res)) |
| 878 | } |
| 879 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 880 | func (fs *flowServer) serve() error { |
| 881 | defer fs.flow.Close() |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 882 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 883 | results, err := fs.processRequest() |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 884 | |
Matt Rosencrantz | 1fa3277 | 2014-10-28 11:31:46 -0700 | [diff] [blame] | 885 | ivtrace.FromContext(fs).Finish() |
| 886 | |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 887 | var traceResponse vtrace.Response |
| 888 | if fs.allowDebug { |
| 889 | traceResponse = ivtrace.Response(fs) |
| 890 | } |
| 891 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 892 | // Respond to the client with the response header and positional results. |
| 893 | response := ipc.Response{ |
| 894 | Error: err, |
| 895 | EndStreamResults: true, |
| 896 | NumPosResults: uint64(len(results)), |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 897 | TraceResponse: traceResponse, |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 898 | } |
| 899 | if err := fs.enc.Encode(response); err != nil { |
Cosmos Nicolaou | 1534b3f | 2014-12-10 15:30:00 -0800 | [diff] [blame] | 900 | if err == io.EOF { |
| 901 | return err |
| 902 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 903 | return old_verror.BadProtocolf("ipc: response encoding failed: %v", err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 904 | } |
| 905 | if response.Error != nil { |
| 906 | return response.Error |
| 907 | } |
| 908 | for ix, res := range results { |
Todd Wang | 34ed4c6 | 2014-11-26 15:15:52 -0800 | [diff] [blame] | 909 | if err := fs.encodeValueHack(res); err != nil { |
Cosmos Nicolaou | 1534b3f | 2014-12-10 15:30:00 -0800 | [diff] [blame] | 910 | if err == io.EOF { |
| 911 | return err |
| 912 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 913 | return old_verror.BadProtocolf("ipc: result #%d [%T=%v] encoding failed: %v", ix, res, res, err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | // TODO(ashankar): Should unread data from the flow be drained? |
| 917 | // |
| 918 | // Reason to do so: |
| 919 | // The common stream.Flow implementation (veyron/runtimes/google/ipc/stream/vc/reader.go) |
| 920 | // uses iobuf.Slices backed by an iobuf.Pool. If the stream is not drained, these |
| 921 | // slices will not be returned to the pool leading to possibly increased memory usage. |
| 922 | // |
| 923 | // Reason to not do so: |
| 924 | // Draining here will conflict with any Reads on the flow in a separate goroutine |
| 925 | // (for example, see TestStreamReadTerminatedByServer in full_test.go). |
| 926 | // |
| 927 | // For now, go with the reason to not do so as having unread data in the stream |
| 928 | // should be a rare case. |
| 929 | return nil |
| 930 | } |
| 931 | |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 932 | func (fs *flowServer) readIPCRequest() (*ipc.Request, old_verror.E) { |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 933 | // Set a default timeout before reading from the flow. Without this timeout, |
| 934 | // a client that sends no request or a partial request will retain the flow |
| 935 | // indefinitely (and lock up server resources). |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 936 | initTimer := newTimer(defaultCallTimeout) |
| 937 | defer initTimer.Stop() |
| 938 | fs.flow.SetDeadline(initTimer.C) |
| 939 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 940 | // Decode the initial request. |
| 941 | var req ipc.Request |
| 942 | if err := fs.dec.Decode(&req); err != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 943 | return nil, old_verror.BadProtocolf("ipc: request decoding failed: %v", err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 944 | } |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 945 | return &req, nil |
| 946 | } |
| 947 | |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 948 | func (fs *flowServer) processRequest() ([]interface{}, old_verror.E) { |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 949 | fs.starttime = time.Now() |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 950 | req, verr := fs.readIPCRequest() |
| 951 | if verr != nil { |
Matt Rosencrantz | 1fa3277 | 2014-10-28 11:31:46 -0700 | [diff] [blame] | 952 | // We don't know what the ipc call was supposed to be, but we'll create |
| 953 | // a placeholder span so we can capture annotations. |
Matt Rosencrantz | 3197d6c | 2014-11-06 09:53:22 -0800 | [diff] [blame] | 954 | fs.T, _ = ivtrace.WithNewSpan(fs, fmt.Sprintf("\"%s\".UNKNOWN", fs.Name())) |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 955 | return nil, verr |
| 956 | } |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 957 | fs.method = req.Method |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 958 | fs.suffix = strings.TrimLeft(req.Suffix, "/") |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 959 | |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 960 | // TODO(mattr): Currently this allows users to trigger trace collection |
| 961 | // on the server even if they will not be allowed to collect the |
Matt Rosencrantz | 3197d6c | 2014-11-06 09:53:22 -0800 | [diff] [blame] | 962 | // results later. This might be considered a DOS vector. |
| 963 | spanName := fmt.Sprintf("\"%s\".%s", fs.Name(), fs.Method()) |
Matt Rosencrantz | 3e76f28 | 2014-11-10 09:38:57 -0800 | [diff] [blame] | 964 | fs.T, _ = ivtrace.WithContinuedSpan(fs, spanName, req.TraceRequest, fs.server.traceStore) |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 965 | |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 966 | var cancel context.CancelFunc |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 967 | if req.Timeout != ipc.NoTimeout { |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 968 | fs.T, cancel = fs.WithDeadline(fs.starttime.Add(time.Duration(req.Timeout))) |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 969 | } else { |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 970 | fs.T, cancel = fs.WithCancel() |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 971 | } |
Matt Rosencrantz | 8689793 | 2014-10-02 09:34:34 -0700 | [diff] [blame] | 972 | fs.flow.SetDeadline(fs.Done()) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 973 | go fs.cancelContextOnClose(cancel) |
Matt Rosencrantz | 137b8d2 | 2014-08-18 09:56:15 -0700 | [diff] [blame] | 974 | |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 975 | // Initialize security: blessings, discharges, etc. |
| 976 | if verr := fs.initSecurity(req); verr != nil { |
| 977 | return nil, verr |
Andres Erbsen | b7f95f3 | 2014-07-07 12:07:56 -0700 | [diff] [blame] | 978 | } |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 979 | // Lookup the invoker. |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 980 | invoker, auth, verr := fs.lookup(fs.suffix, &fs.method) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 981 | if verr != nil { |
| 982 | return nil, verr |
| 983 | } |
| 984 | // Prepare invoker and decode args. |
| 985 | numArgs := int(req.NumPosArgs) |
Robin Thellend | b16d716 | 2014-11-07 13:47:26 -0800 | [diff] [blame] | 986 | argptrs, tags, err := invoker.Prepare(fs.method, numArgs) |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 987 | fs.tags = tags |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 988 | if err != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 989 | return nil, old_verror.Makef(old_verror.ErrorID(err), "%s: name: %q", err, fs.suffix) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 990 | } |
| 991 | if len(argptrs) != numArgs { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 992 | return nil, old_verror.BadProtocolf(fmt.Sprintf("ipc: wrong number of input arguments for method %q, name %q (called with %d args, expected %d)", fs.method, fs.suffix, numArgs, len(argptrs))) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 993 | } |
| 994 | for ix, argptr := range argptrs { |
| 995 | if err := fs.dec.Decode(argptr); err != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 996 | return nil, old_verror.BadProtocolf("ipc: arg %d decoding failed: %v", ix, err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 999 | // Check application's authorization policy. |
| 1000 | if verr := authorize(fs, auth); verr != nil { |
| 1001 | return nil, verr |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1002 | } |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1003 | // Check if the caller is permitted to view debug information. |
Asim Shankar | 6888519 | 2014-11-26 12:48:35 -0800 | [diff] [blame] | 1004 | // TODO(mattr): Is access.Debug the right thing to check? |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1005 | fs.allowDebug = authorize(debugContext{fs}, auth) == nil |
| 1006 | // Invoke the method. |
Robin Thellend | b16d716 | 2014-11-07 13:47:26 -0800 | [diff] [blame] | 1007 | results, err := invoker.Invoke(fs.method, fs, argptrs) |
| 1008 | fs.server.stats.record(fs.method, time.Since(fs.starttime)) |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1009 | return results, old_verror.Convert(err) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1012 | func (fs *flowServer) cancelContextOnClose(cancel context.CancelFunc) { |
| 1013 | // Ensure that the context gets cancelled if the flow is closed |
| 1014 | // due to a network error, or client cancellation. |
| 1015 | select { |
| 1016 | case <-fs.flow.Closed(): |
| 1017 | // Here we remove the contexts channel as a deadline to the flow. |
| 1018 | // We do this to ensure clients get a consistent error when they read/write |
| 1019 | // after the flow is closed. Since the flow is already closed, it doesn't |
| 1020 | // matter that the context is also cancelled. |
| 1021 | fs.flow.SetDeadline(nil) |
| 1022 | cancel() |
| 1023 | case <-fs.Done(): |
Robin Thellend | c26c32e | 2014-10-06 17:44:04 -0700 | [diff] [blame] | 1024 | } |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | // lookup returns the invoker and authorizer responsible for serving the given |
| 1028 | // name and method. The suffix is stripped of any leading slashes. If it begins |
| 1029 | // with ipc.DebugKeyword, we use the internal debug dispatcher to look up the |
| 1030 | // invoker. Otherwise, and we use the server's dispatcher. The suffix and method |
| 1031 | // value may be modified to match the actual suffix and method to use. |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1032 | func (fs *flowServer) lookup(suffix string, method *string) (ipc.Invoker, security.Authorizer, old_verror.E) { |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1033 | if naming.IsReserved(*method) { |
| 1034 | // All reserved methods are trapped and handled here, by removing the |
| 1035 | // reserved prefix and invoking them on reservedMethods. E.g. "__Glob" |
| 1036 | // invokes reservedMethods.Glob. |
| 1037 | *method = naming.StripReserved(*method) |
| 1038 | return reservedInvoker(fs.disp, fs.server.dispReserved), &acceptAllAuthorizer{}, nil |
| 1039 | } |
| 1040 | disp := fs.disp |
| 1041 | if naming.IsReserved(suffix) { |
| 1042 | disp = fs.server.dispReserved |
Robin Thellend | d24f084 | 2014-09-23 10:27:29 -0700 | [diff] [blame] | 1043 | } |
| 1044 | if disp != nil { |
Robin Thellend | a02fe8f | 2014-11-19 09:58:29 -0800 | [diff] [blame] | 1045 | obj, auth, err := disp.Lookup(suffix) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1046 | switch { |
| 1047 | case err != nil: |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1048 | return nil, nil, old_verror.Convert(err) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1049 | case obj != nil: |
| 1050 | return objectToInvoker(obj), auth, nil |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1051 | } |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1052 | } |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1053 | return nil, nil, old_verror.NoExistf("ipc: invoker not found for %q", suffix) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | func objectToInvoker(obj interface{}) ipc.Invoker { |
| 1057 | if obj == nil { |
| 1058 | return nil |
| 1059 | } |
| 1060 | if invoker, ok := obj.(ipc.Invoker); ok { |
| 1061 | return invoker |
| 1062 | } |
| 1063 | return ipc.ReflectInvoker(obj) |
| 1064 | } |
| 1065 | |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1066 | func (fs *flowServer) initSecurity(req *ipc.Request) old_verror.E { |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1067 | // If additional credentials are provided, make them available in the context |
| 1068 | blessings, err := security.NewBlessings(req.GrantedBlessings) |
| 1069 | if err != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1070 | return old_verror.BadProtocolf("ipc: failed to decode granted blessings: %v", err) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1071 | } |
| 1072 | fs.blessings = blessings |
| 1073 | // Detect unusable blessings now, rather then discovering they are unusable on |
| 1074 | // first use. |
| 1075 | // |
| 1076 | // TODO(ashankar,ataly): Potential confused deputy attack: The client provides |
| 1077 | // the server's identity as the blessing. Figure out what we want to do about |
| 1078 | // this - should servers be able to assume that a blessing is something that |
| 1079 | // does not have the authorizations that the server's own identity has? |
| 1080 | if blessings != nil && !reflect.DeepEqual(blessings.PublicKey(), fs.flow.LocalPrincipal().PublicKey()) { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1081 | return old_verror.NoAccessf("ipc: blessing granted not bound to this server(%v vs %v)", blessings.PublicKey(), fs.flow.LocalPrincipal().PublicKey()) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1082 | } |
| 1083 | // Receive third party caveat discharges the client sent |
| 1084 | for i := uint64(0); i < req.NumDischarges; i++ { |
| 1085 | var d security.Discharge |
| 1086 | if err := fs.dec.Decode(&d); err != nil { |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1087 | return old_verror.BadProtocolf("ipc: decoding discharge %d of %d failed: %v", i, req.NumDischarges, err) |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1088 | } |
| 1089 | fs.discharges[d.ID()] = d |
| 1090 | } |
| 1091 | return nil |
Robin Thellend | c26c32e | 2014-10-06 17:44:04 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | type acceptAllAuthorizer struct{} |
| 1095 | |
| 1096 | func (acceptAllAuthorizer) Authorize(security.Context) error { |
| 1097 | return nil |
| 1098 | } |
| 1099 | |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1100 | func authorize(ctx security.Context, auth security.Authorizer) old_verror.E { |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1101 | if ctx.LocalPrincipal() == nil { |
| 1102 | // LocalPrincipal is nil means that the server wanted to avoid |
| 1103 | // authentication, and thus wanted to skip authorization as well. |
| 1104 | return nil |
| 1105 | } |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1106 | if auth == nil { |
Asim Shankar | 0c73fbf | 2014-10-31 15:34:02 -0700 | [diff] [blame] | 1107 | auth = defaultAuthorizer{} |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1108 | } |
Todd Wang | 5739dda | 2014-11-16 22:44:02 -0800 | [diff] [blame] | 1109 | if err := auth.Authorize(ctx); err != nil { |
Asim Shankar | a5457f0 | 2014-10-24 23:23:07 -0700 | [diff] [blame] | 1110 | // TODO(ataly, ashankar): For privacy reasons, should we hide the authorizer error? |
Cosmos Nicolaou | 28dabfc | 2014-12-15 22:51:07 -0800 | [diff] [blame] | 1111 | return old_verror.NoAccessf("ipc: not authorized to call %q.%q (%v)", ctx.Suffix(), ctx.Method(), err) |
Asim Shankar | a5457f0 | 2014-10-24 23:23:07 -0700 | [diff] [blame] | 1112 | } |
| 1113 | return nil |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 1116 | // debugContext is a context which wraps another context but always returns |
Asim Shankar | 6888519 | 2014-11-26 12:48:35 -0800 | [diff] [blame] | 1117 | // the debug tag. |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 1118 | type debugContext struct { |
| 1119 | security.Context |
| 1120 | } |
| 1121 | |
Asim Shankar | 6888519 | 2014-11-26 12:48:35 -0800 | [diff] [blame] | 1122 | func (debugContext) MethodTags() []interface{} { |
| 1123 | return []interface{}{access.Debug} |
| 1124 | } |
Matt Rosencrantz | 9fe6082 | 2014-09-12 10:09:53 -0700 | [diff] [blame] | 1125 | |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1126 | // Send implements the ipc.Stream method. |
| 1127 | func (fs *flowServer) Send(item interface{}) error { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1128 | defer vlog.LogCall()() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1129 | // The empty response header indicates what follows is a streaming result. |
| 1130 | if err := fs.enc.Encode(ipc.Response{}); err != nil { |
| 1131 | return err |
| 1132 | } |
| 1133 | return fs.enc.Encode(item) |
| 1134 | } |
| 1135 | |
| 1136 | // Recv implements the ipc.Stream method. |
| 1137 | func (fs *flowServer) Recv(itemptr interface{}) error { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1138 | defer vlog.LogCall()() |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1139 | var req ipc.Request |
| 1140 | if err := fs.dec.Decode(&req); err != nil { |
| 1141 | return err |
| 1142 | } |
| 1143 | if req.EndStreamArgs { |
| 1144 | fs.endStreamArgs = true |
| 1145 | return io.EOF |
| 1146 | } |
| 1147 | return fs.dec.Decode(itemptr) |
| 1148 | } |
| 1149 | |
Matt Rosencrantz | f5afcaf | 2014-06-02 11:31:22 -0700 | [diff] [blame] | 1150 | // Implementations of ipc.ServerContext methods. |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1151 | |
Asim Shankar | 2519cc1 | 2014-11-10 21:16:53 -0800 | [diff] [blame] | 1152 | func (fs *flowServer) RemoteDischarges() map[string]security.Discharge { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1153 | //nologcall |
| 1154 | return fs.discharges |
| 1155 | } |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1156 | func (fs *flowServer) Server() ipc.Server { |
| 1157 | //nologcall |
| 1158 | return fs.server |
| 1159 | } |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 1160 | func (fs *flowServer) Timestamp() time.Time { |
| 1161 | //nologcall |
| 1162 | return fs.starttime |
| 1163 | } |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1164 | func (fs *flowServer) Method() string { |
| 1165 | //nologcall |
| 1166 | return fs.method |
| 1167 | } |
Asim Shankar | 0cad083 | 2014-11-04 01:27:38 -0800 | [diff] [blame] | 1168 | func (fs *flowServer) MethodTags() []interface{} { |
| 1169 | //nologcall |
| 1170 | return fs.tags |
| 1171 | } |
Matt Rosencrantz | 04d197c | 2014-12-12 08:39:25 -0800 | [diff] [blame] | 1172 | func (fs *flowServer) Context() context.T { |
| 1173 | return fs.T |
| 1174 | } |
Cosmos Nicolaou | fdc838b | 2014-06-30 21:44:27 -0700 | [diff] [blame] | 1175 | |
| 1176 | // TODO(cnicolaou): remove Name from ipc.ServerContext and all of |
| 1177 | // its implementations |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1178 | func (fs *flowServer) Name() string { |
| 1179 | //nologcall |
| 1180 | return fs.suffix |
| 1181 | } |
| 1182 | func (fs *flowServer) Suffix() string { |
| 1183 | //nologcall |
| 1184 | return fs.suffix |
| 1185 | } |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1186 | func (fs *flowServer) LocalPrincipal() security.Principal { |
| 1187 | //nologcall |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1188 | return fs.flow.LocalPrincipal() |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1189 | } |
| 1190 | func (fs *flowServer) LocalBlessings() security.Blessings { |
| 1191 | //nologcall |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1192 | return fs.flow.LocalBlessings() |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1193 | } |
| 1194 | func (fs *flowServer) RemoteBlessings() security.Blessings { |
| 1195 | //nologcall |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1196 | return fs.flow.RemoteBlessings() |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1197 | } |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1198 | func (fs *flowServer) Blessings() security.Blessings { |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1199 | //nologcall |
Asim Shankar | 8f05c22 | 2014-10-06 22:08:19 -0700 | [diff] [blame] | 1200 | return fs.blessings |
Mehrdad Afshari | cd9852b | 2014-09-26 11:07:35 -0700 | [diff] [blame] | 1201 | } |
| 1202 | func (fs *flowServer) LocalEndpoint() naming.Endpoint { |
| 1203 | //nologcall |
| 1204 | return fs.flow.LocalEndpoint() |
| 1205 | } |
| 1206 | func (fs *flowServer) RemoteEndpoint() naming.Endpoint { |
| 1207 | //nologcall |
| 1208 | return fs.flow.RemoteEndpoint() |
| 1209 | } |