summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-04-10 15:43:41 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-04-11 05:44:30 +0900
commitd4a82f70ba17b64b1841d801098bf38dc0c475e1 (patch)
treef4a03088be1d1a11432cd539a28e727c9e4d3192 /server
parent0d2633e7831cb2406bacf62a232fcca7184ff988 (diff)
specify api hosts that gobgpd listens on
by default, ":50051" is used as before. gobgpd accepts grpc connections from localhost with the following example: $ gobgpd --api-hosts 127.0.0.1:50051 You can specify multiple hosts like: $ gobgpd --api-hosts 127.0.0.1:50051,10.0.255.254:50051 close #796 Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index cff759ff..cf0a883d 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -24,6 +24,7 @@ import (
"google.golang.org/grpc"
"io"
"net"
+ "strings"
)
const (
@@ -79,15 +80,24 @@ const (
type Server struct {
grpcServer *grpc.Server
bgpServerCh chan *GrpcRequest
- port int
+ hosts string
}
func (s *Server) Serve() error {
- lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.port))
- if err != nil {
- return fmt.Errorf("failed to listen: %v", err)
+ l := strings.Split(s.hosts, ",")
+ for i, host := range l {
+ lis, err := net.Listen("tcp", fmt.Sprintf(host))
+ if err != nil {
+ return fmt.Errorf("failed to listen: %v", err)
+ }
+ if i == len(l)-1 {
+ s.grpcServer.Serve(lis)
+ } else {
+ go func() {
+ s.grpcServer.Serve(lis)
+ }()
+ }
}
- s.grpcServer.Serve(lis)
return nil
}
@@ -482,13 +492,13 @@ func (r *GrpcResponse) Err() error {
return r.ResponseErr
}
-func NewGrpcServer(port int, bgpServerCh chan *GrpcRequest) *Server {
+func NewGrpcServer(hosts string, bgpServerCh chan *GrpcRequest) *Server {
grpc.EnableTracing = false
grpcServer := grpc.NewServer()
server := &Server{
grpcServer: grpcServer,
bgpServerCh: bgpServerCh,
- port: port,
+ hosts: hosts,
}
api.RegisterGobgpApiServer(grpcServer, server)
return server