├── .gitignore ├── go.mod ├── Makefile ├── README.md ├── gcgrpc ├── gcgrpc.proto └── gcgrpc.pb.go ├── go.sum ├── gcgrpcpool_test.go ├── gcgrpcpool.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/charithe/gcgrpcpool 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef 7 | github.com/golang/protobuf v1.2.0 8 | github.com/sirupsen/logrus v1.4.1 9 | golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 10 | google.golang.org/grpc v1.20.1 11 | ) 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROTO_DIR=gcgrpc 2 | PROTO_BASENAME=gcgrpc 3 | PROTO_TARGET=$(PROTO_DIR)/$(PROTO_BASENAME).pb.go 4 | 5 | all: $(PROTO_TARGET) 6 | 7 | $(PROTO_TARGET): 8 | protoc -I $(PROTO_DIR) --go_out=plugins=grpc:$(PROTO_DIR) $(PROTO_DIR)/$(PROTO_BASENAME).proto 9 | 10 | test: 11 | go test 12 | 13 | clean: 14 | -rm -rf $(PROTO_TARGET) 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GRPC pool for groupcache 2 | ======================== 3 | 4 | A replacement for [groupcache](https://github.com/golang/groupcache) `HTTPPool` that uses GRPC to communicate with peers. 5 | 6 | 7 | Usage 8 | ----- 9 | 10 | ```go 11 | server := grpc.NewServer() 12 | 13 | p := NewGRPCPool("127.0.0.1:5000", server) 14 | p.Set(peerAddrs...) 15 | 16 | getter := groupcache.GetterFunc(func(ctx groupcache.Context, key string, dest groupcache.Sink) error { 17 | dest.SetString(...) 18 | return nil 19 | }) 20 | 21 | groupcache.NewGroup("grpcPool", 1<<20, getter) 22 | lis, err := net.Listen("tcp", "127.0.0.1:5000") 23 | if err != nil { 24 | log.Fatalf("Failed to start server") 25 | } 26 | 27 | server.Serve(lis) 28 | ``` 29 | 30 | Use `GRPCPoolOptions` to set the GRPC client dial options such as using compression, authentication etc. 31 | 32 | To Do 33 | ----- 34 | 35 | - Use GRPC `Balancer` to manage the peer connections 36 | - Peer discovery mechanism for Kubernetes 37 | -------------------------------------------------------------------------------- /gcgrpc/gcgrpc.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Charith Ellawala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | syntax = "proto3"; 18 | package gcgrpc; 19 | 20 | message RetrieveRequest { 21 | string group = 1; 22 | string key = 2; 23 | } 24 | 25 | message RetrieveResponse { 26 | bytes value = 1; 27 | } 28 | 29 | message Peers { 30 | repeated string peerAddr = 1; 31 | } 32 | 33 | message Ack {} 34 | 35 | service Peer { 36 | rpc Retrieve(RetrieveRequest) returns (RetrieveResponse) {} 37 | rpc AddPeers(Peers) returns (Ack) {} 38 | rpc RemovePeers(Peers) returns (Ack) {} 39 | rpc SetPeers(Peers) returns (Ack) {} 40 | } 41 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/charithe/gcgrpcpool v0.0.0-20160710140113-3972289b8c74 h1:oMZc64h2wIi9UyT/NzB8zuurmkZd29AQdEpWtzZsi8Q= 4 | github.com/charithe/gcgrpcpool v0.0.0-20160710140113-3972289b8c74/go.mod h1:uI72MHzHZTPh0Iil6wHPy1evOF4UCnYbzF04M4DKhmY= 5 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 6 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= 9 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 10 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= 11 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 12 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 13 | github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= 14 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= 16 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 17 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 18 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 19 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 20 | github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= 21 | github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= 22 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 23 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= 24 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 25 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 26 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 27 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 28 | golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 h1:FP8hkuE6yUEaJnK7O2eTuejKWwW+Rhfj80dQ2JcKxCU= 29 | golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 30 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 31 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 32 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 33 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= 34 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 35 | golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= 36 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 37 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 38 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 39 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= 40 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 41 | google.golang.org/grpc v1.20.1 h1:Hz2g2wirWK7H0qIIhGIqRGTuMwTE8HEKFnDZZ7lm9NU= 42 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 43 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 44 | -------------------------------------------------------------------------------- /gcgrpcpool_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Adapted from https://github.com/golang/groupcache/blob/master/http_test.go 3 | */ 4 | 5 | package gcgrpcpool 6 | 7 | import ( 8 | "errors" 9 | "flag" 10 | "log" 11 | "net" 12 | "os" 13 | "os/exec" 14 | "strconv" 15 | "strings" 16 | "sync" 17 | "testing" 18 | "time" 19 | 20 | "github.com/golang/groupcache" 21 | "google.golang.org/grpc" 22 | ) 23 | 24 | var ( 25 | peerAddrs = flag.String("test_peer_addrs", "", "Comma-separated list of peer addresses; used by TestGRPCPool") 26 | peerIndex = flag.Int("test_peer_index", -1, "Index of which peer this child is; used by TestGRPCPool") 27 | peerChild = flag.Bool("test_peer_child", false, "True if running as a child process; used by TestGRPCPool") 28 | ) 29 | 30 | func TestGRPCPool(t *testing.T) { 31 | if *peerChild { 32 | beChildForTestGRPCPool() 33 | os.Exit(0) 34 | } 35 | 36 | const ( 37 | nChild = 5 38 | nGets = 5000 39 | ) 40 | 41 | var childAddr []string 42 | for i := 0; i < nChild; i++ { 43 | childAddr = append(childAddr, pickFreeAddr(t)) 44 | } 45 | 46 | var cmds []*exec.Cmd 47 | var wg sync.WaitGroup 48 | for i := 0; i < nChild; i++ { 49 | cmd := exec.Command(os.Args[0], 50 | "--test.run=TestGRPCPool", 51 | "--test_peer_child", 52 | "--test_peer_addrs="+strings.Join(childAddr, ","), 53 | "--test_peer_index="+strconv.Itoa(i), 54 | ) 55 | cmds = append(cmds, cmd) 56 | wg.Add(1) 57 | if err := cmd.Start(); err != nil { 58 | t.Fatal("failed to start child process: ", err) 59 | } 60 | go awaitAddrReady(t, childAddr[i], &wg) 61 | } 62 | defer func() { 63 | for i := 0; i < nChild; i++ { 64 | if cmds[i].Process != nil { 65 | cmds[i].Process.Kill() 66 | } 67 | } 68 | }() 69 | wg.Wait() 70 | 71 | // Use a dummy self address so that we don't handle gets in-process. 72 | p := NewGRPCPool("should-be-ignored", grpc.NewServer()) 73 | p.Set(childAddr...) 74 | 75 | // Dummy getter function. Gets should go to children only. 76 | // The only time this process will handle a get is when the 77 | // children can't be contacted for some reason. 78 | getter := groupcache.GetterFunc(func(ctx groupcache.Context, key string, dest groupcache.Sink) error { 79 | return errors.New("parent getter called; something's wrong") 80 | }) 81 | g := groupcache.NewGroup("grpcPoolTest", 1<<20, getter) 82 | 83 | for _, key := range testKeys(nGets) { 84 | var value string 85 | if err := g.Get(nil, key, groupcache.StringSink(&value)); err != nil { 86 | t.Fatal(err) 87 | } 88 | if suffix := ":" + key; !strings.HasSuffix(value, suffix) { 89 | t.Errorf("Get(%q) = %q, want value ending in %q", key, value, suffix) 90 | } 91 | t.Logf("Get key=%q, value=%q (peer:key)", key, value) 92 | } 93 | } 94 | 95 | func testKeys(n int) (keys []string) { 96 | keys = make([]string, n) 97 | for i := range keys { 98 | keys[i] = strconv.Itoa(i) 99 | } 100 | return 101 | } 102 | 103 | func beChildForTestGRPCPool() { 104 | addrs := strings.Split(*peerAddrs, ",") 105 | server := grpc.NewServer() 106 | 107 | p := NewGRPCPool(addrs[*peerIndex], server) 108 | p.Set(addrs...) 109 | 110 | getter := groupcache.GetterFunc(func(ctx groupcache.Context, key string, dest groupcache.Sink) error { 111 | dest.SetString(strconv.Itoa(*peerIndex) + ":" + key) 112 | return nil 113 | }) 114 | groupcache.NewGroup("grpcPoolTest", 1<<20, getter) 115 | lis, err := net.Listen("tcp", addrs[*peerIndex]) 116 | if err != nil { 117 | log.Fatalf("Failed to listen on %s", addrs[*peerIndex]) 118 | } 119 | 120 | server.Serve(lis) 121 | } 122 | 123 | func pickFreeAddr(t *testing.T) string { 124 | l, err := net.Listen("tcp", "127.0.0.1:0") 125 | if err != nil { 126 | t.Fatal(err) 127 | } 128 | defer l.Close() 129 | return l.Addr().String() 130 | } 131 | 132 | func awaitAddrReady(t *testing.T, addr string, wg *sync.WaitGroup) { 133 | defer wg.Done() 134 | const max = 1 * time.Second 135 | tries := 0 136 | for { 137 | tries++ 138 | c, err := net.Dial("tcp", addr) 139 | if err == nil { 140 | c.Close() 141 | return 142 | } 143 | delay := time.Duration(tries) * 25 * time.Millisecond 144 | if delay > max { 145 | delay = max 146 | } 147 | time.Sleep(delay) 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /gcgrpcpool.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Charith Ellawala 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package gcgrpcpool 17 | 18 | import ( 19 | "fmt" 20 | "sync" 21 | 22 | log "github.com/sirupsen/logrus" 23 | 24 | "github.com/charithe/gcgrpcpool/gcgrpc" 25 | "github.com/golang/groupcache" 26 | "github.com/golang/groupcache/consistenthash" 27 | pb "github.com/golang/groupcache/groupcachepb" 28 | "golang.org/x/net/context" 29 | "google.golang.org/grpc" 30 | ) 31 | 32 | const defaultReplicas = 50 33 | 34 | type GRPCPool struct { 35 | self string 36 | opts GRPCPoolOptions 37 | mu sync.Mutex 38 | peers *consistenthash.Map 39 | grpcGetters map[string]*grpcGetter 40 | } 41 | 42 | type GRPCPoolOptions struct { 43 | Replicas int 44 | HashFn consistenthash.Hash 45 | PeerDialOptions []grpc.DialOption 46 | } 47 | 48 | func NewGRPCPool(self string, server *grpc.Server) *GRPCPool { 49 | return NewGRPCPoolOptions(self, server, nil) 50 | } 51 | 52 | var grpcPoolCreated bool 53 | 54 | func NewGRPCPoolOptions(self string, server *grpc.Server, opts *GRPCPoolOptions) *GRPCPool { 55 | if grpcPoolCreated { 56 | panic("NewGRPCPool must be called only once") 57 | } 58 | 59 | grpcPoolCreated = true 60 | 61 | pool := &GRPCPool{ 62 | self: self, 63 | grpcGetters: make(map[string]*grpcGetter), 64 | } 65 | 66 | if opts != nil { 67 | pool.opts = *opts 68 | } 69 | 70 | if pool.opts.Replicas == 0 { 71 | pool.opts.Replicas = defaultReplicas 72 | } 73 | 74 | if pool.opts.PeerDialOptions == nil { 75 | pool.opts.PeerDialOptions = []grpc.DialOption{grpc.WithInsecure()} 76 | } 77 | 78 | pool.peers = consistenthash.New(pool.opts.Replicas, pool.opts.HashFn) 79 | groupcache.RegisterPeerPicker(func() groupcache.PeerPicker { return pool }) 80 | gcgrpc.RegisterPeerServer(server, pool) 81 | return pool 82 | } 83 | 84 | func (gp *GRPCPool) Set(peers ...string) { 85 | gp.mu.Lock() 86 | defer gp.mu.Unlock() 87 | gp.peers = consistenthash.New(gp.opts.Replicas, gp.opts.HashFn) 88 | tempGetters := make(map[string]*grpcGetter, len(peers)) 89 | for _, peer := range peers { 90 | if getter, exists := gp.grpcGetters[peer]; exists == true { 91 | tempGetters[peer] = getter 92 | gp.peers.Add(peer) 93 | delete(gp.grpcGetters, peer) 94 | } else { 95 | getter, err := newGRPCGetter(peer, gp.opts.PeerDialOptions...) 96 | if err != nil { 97 | log.WithError(err).Warnf("Failed to open connection to [%s]", peer) 98 | } else { 99 | tempGetters[peer] = getter 100 | gp.peers.Add(peer) 101 | } 102 | } 103 | } 104 | 105 | for p, g := range gp.grpcGetters { 106 | g.close() 107 | delete(gp.grpcGetters, p) 108 | } 109 | 110 | gp.grpcGetters = tempGetters 111 | } 112 | 113 | func (gp *GRPCPool) PickPeer(key string) (groupcache.ProtoGetter, bool) { 114 | gp.mu.Lock() 115 | defer gp.mu.Unlock() 116 | 117 | if gp.peers.IsEmpty() { 118 | return nil, false 119 | } 120 | 121 | if peer := gp.peers.Get(key); peer != gp.self { 122 | return gp.grpcGetters[peer], true 123 | } 124 | return nil, false 125 | } 126 | 127 | func (gp *GRPCPool) Retrieve(ctx context.Context, req *gcgrpc.RetrieveRequest) (*gcgrpc.RetrieveResponse, error) { 128 | group := groupcache.GetGroup(req.Group) 129 | if group == nil { 130 | log.Warnf("Unable to find group [%s]", req.Group) 131 | return nil, fmt.Errorf("Unable to find group [%s]", req.Group) 132 | } 133 | group.Stats.ServerRequests.Add(1) 134 | var value []byte 135 | err := group.Get(ctx, req.Key, groupcache.AllocatingByteSliceSink(&value)) 136 | if err != nil { 137 | log.WithError(err).Warnf("Failed to retrieve [%s]", req) 138 | return nil, fmt.Errorf("Failed to retrieve [%s]: %v", req, err) 139 | } 140 | 141 | return &gcgrpc.RetrieveResponse{Value: value}, nil 142 | } 143 | 144 | func (gp *GRPCPool) AddPeers(ctx context.Context, peers *gcgrpc.Peers) (*gcgrpc.Ack, error) { 145 | gp.mu.Lock() 146 | defer gp.mu.Unlock() 147 | for _, peer := range peers.PeerAddr { 148 | if _, exists := gp.grpcGetters[peer]; exists != true { 149 | getter, err := newGRPCGetter(peer, gp.opts.PeerDialOptions...) 150 | if err != nil { 151 | log.WithError(err).Warnf("Failed to open connection to [%s]", peer) 152 | } else { 153 | log.Infof("Adding peer [%s]", peer) 154 | gp.grpcGetters[peer] = getter 155 | gp.peers.Add(peer) 156 | } 157 | } 158 | } 159 | return &gcgrpc.Ack{}, nil 160 | 161 | } 162 | 163 | func (gp *GRPCPool) RemovePeers(ctx context.Context, peers *gcgrpc.Peers) (*gcgrpc.Ack, error) { 164 | gp.mu.Lock() 165 | defer gp.mu.Unlock() 166 | for _, peer := range peers.PeerAddr { 167 | if p, exists := gp.grpcGetters[peer]; exists == true { 168 | log.Infof("Removing peer [%s]", peer) 169 | p.close() 170 | delete(gp.grpcGetters, peer) 171 | } 172 | } 173 | return &gcgrpc.Ack{}, nil 174 | } 175 | 176 | func (gp *GRPCPool) SetPeers(ctx context.Context, peers *gcgrpc.Peers) (*gcgrpc.Ack, error) { 177 | gp.Set(peers.PeerAddr...) 178 | return &gcgrpc.Ack{}, nil 179 | } 180 | 181 | type grpcGetter struct { 182 | address string 183 | conn *grpc.ClientConn 184 | } 185 | 186 | func newGRPCGetter(address string, dialOpts ...grpc.DialOption) (*grpcGetter, error) { 187 | conn, err := grpc.Dial(address, dialOpts...) 188 | if err != nil { 189 | return nil, fmt.Errorf("Failed to connect to [%s]: %v", address, err) 190 | } 191 | return &grpcGetter{address: address, conn: conn}, nil 192 | } 193 | 194 | func (g *grpcGetter) Get(ctx groupcache.Context, in *pb.GetRequest, out *pb.GetResponse) error { 195 | client := gcgrpc.NewPeerClient(g.conn) 196 | resp, err := client.Retrieve(context.Background(), &gcgrpc.RetrieveRequest{Group: *in.Group, Key: *in.Key}) 197 | if err != nil { 198 | return fmt.Errorf("Failed to GET [%s]: %v", in, err) 199 | } 200 | 201 | out.Value = resp.Value 202 | return nil 203 | } 204 | 205 | func (g *grpcGetter) close() { 206 | if g.conn != nil { 207 | g.conn.Close() 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /gcgrpc/gcgrpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: gcgrpc.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package gcgrpc is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | gcgrpc.proto 10 | 11 | It has these top-level messages: 12 | RetrieveRequest 13 | RetrieveResponse 14 | Peers 15 | Ack 16 | */ 17 | package gcgrpc 18 | 19 | import proto "github.com/golang/protobuf/proto" 20 | import fmt "fmt" 21 | import math "math" 22 | 23 | import ( 24 | context "golang.org/x/net/context" 25 | grpc "google.golang.org/grpc" 26 | ) 27 | 28 | // Reference imports to suppress errors if they are not otherwise used. 29 | var _ = proto.Marshal 30 | var _ = fmt.Errorf 31 | var _ = math.Inf 32 | 33 | // This is a compile-time assertion to ensure that this generated file 34 | // is compatible with the proto package it is being compiled against. 35 | // A compilation error at this line likely means your copy of the 36 | // proto package needs to be updated. 37 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 38 | 39 | type RetrieveRequest struct { 40 | Group string `protobuf:"bytes,1,opt,name=group" json:"group,omitempty"` 41 | Key string `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"` 42 | } 43 | 44 | func (m *RetrieveRequest) Reset() { *m = RetrieveRequest{} } 45 | func (m *RetrieveRequest) String() string { return proto.CompactTextString(m) } 46 | func (*RetrieveRequest) ProtoMessage() {} 47 | func (*RetrieveRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 48 | 49 | type RetrieveResponse struct { 50 | Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` 51 | } 52 | 53 | func (m *RetrieveResponse) Reset() { *m = RetrieveResponse{} } 54 | func (m *RetrieveResponse) String() string { return proto.CompactTextString(m) } 55 | func (*RetrieveResponse) ProtoMessage() {} 56 | func (*RetrieveResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } 57 | 58 | type Peers struct { 59 | PeerAddr []string `protobuf:"bytes,1,rep,name=peerAddr" json:"peerAddr,omitempty"` 60 | } 61 | 62 | func (m *Peers) Reset() { *m = Peers{} } 63 | func (m *Peers) String() string { return proto.CompactTextString(m) } 64 | func (*Peers) ProtoMessage() {} 65 | func (*Peers) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } 66 | 67 | type Ack struct { 68 | } 69 | 70 | func (m *Ack) Reset() { *m = Ack{} } 71 | func (m *Ack) String() string { return proto.CompactTextString(m) } 72 | func (*Ack) ProtoMessage() {} 73 | func (*Ack) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } 74 | 75 | func init() { 76 | proto.RegisterType((*RetrieveRequest)(nil), "gcgrpc.RetrieveRequest") 77 | proto.RegisterType((*RetrieveResponse)(nil), "gcgrpc.RetrieveResponse") 78 | proto.RegisterType((*Peers)(nil), "gcgrpc.Peers") 79 | proto.RegisterType((*Ack)(nil), "gcgrpc.Ack") 80 | } 81 | 82 | // Reference imports to suppress errors if they are not otherwise used. 83 | var _ context.Context 84 | var _ grpc.ClientConn 85 | 86 | // This is a compile-time assertion to ensure that this generated file 87 | // is compatible with the grpc package it is being compiled against. 88 | const _ = grpc.SupportPackageIsVersion3 89 | 90 | // Client API for Peer service 91 | 92 | type PeerClient interface { 93 | Retrieve(ctx context.Context, in *RetrieveRequest, opts ...grpc.CallOption) (*RetrieveResponse, error) 94 | AddPeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) 95 | RemovePeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) 96 | SetPeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) 97 | } 98 | 99 | type peerClient struct { 100 | cc *grpc.ClientConn 101 | } 102 | 103 | func NewPeerClient(cc *grpc.ClientConn) PeerClient { 104 | return &peerClient{cc} 105 | } 106 | 107 | func (c *peerClient) Retrieve(ctx context.Context, in *RetrieveRequest, opts ...grpc.CallOption) (*RetrieveResponse, error) { 108 | out := new(RetrieveResponse) 109 | err := grpc.Invoke(ctx, "/gcgrpc.Peer/Retrieve", in, out, c.cc, opts...) 110 | if err != nil { 111 | return nil, err 112 | } 113 | return out, nil 114 | } 115 | 116 | func (c *peerClient) AddPeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) { 117 | out := new(Ack) 118 | err := grpc.Invoke(ctx, "/gcgrpc.Peer/AddPeers", in, out, c.cc, opts...) 119 | if err != nil { 120 | return nil, err 121 | } 122 | return out, nil 123 | } 124 | 125 | func (c *peerClient) RemovePeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) { 126 | out := new(Ack) 127 | err := grpc.Invoke(ctx, "/gcgrpc.Peer/RemovePeers", in, out, c.cc, opts...) 128 | if err != nil { 129 | return nil, err 130 | } 131 | return out, nil 132 | } 133 | 134 | func (c *peerClient) SetPeers(ctx context.Context, in *Peers, opts ...grpc.CallOption) (*Ack, error) { 135 | out := new(Ack) 136 | err := grpc.Invoke(ctx, "/gcgrpc.Peer/SetPeers", in, out, c.cc, opts...) 137 | if err != nil { 138 | return nil, err 139 | } 140 | return out, nil 141 | } 142 | 143 | // Server API for Peer service 144 | 145 | type PeerServer interface { 146 | Retrieve(context.Context, *RetrieveRequest) (*RetrieveResponse, error) 147 | AddPeers(context.Context, *Peers) (*Ack, error) 148 | RemovePeers(context.Context, *Peers) (*Ack, error) 149 | SetPeers(context.Context, *Peers) (*Ack, error) 150 | } 151 | 152 | func RegisterPeerServer(s *grpc.Server, srv PeerServer) { 153 | s.RegisterService(&_Peer_serviceDesc, srv) 154 | } 155 | 156 | func _Peer_Retrieve_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 157 | in := new(RetrieveRequest) 158 | if err := dec(in); err != nil { 159 | return nil, err 160 | } 161 | if interceptor == nil { 162 | return srv.(PeerServer).Retrieve(ctx, in) 163 | } 164 | info := &grpc.UnaryServerInfo{ 165 | Server: srv, 166 | FullMethod: "/gcgrpc.Peer/Retrieve", 167 | } 168 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 169 | return srv.(PeerServer).Retrieve(ctx, req.(*RetrieveRequest)) 170 | } 171 | return interceptor(ctx, in, info, handler) 172 | } 173 | 174 | func _Peer_AddPeers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 175 | in := new(Peers) 176 | if err := dec(in); err != nil { 177 | return nil, err 178 | } 179 | if interceptor == nil { 180 | return srv.(PeerServer).AddPeers(ctx, in) 181 | } 182 | info := &grpc.UnaryServerInfo{ 183 | Server: srv, 184 | FullMethod: "/gcgrpc.Peer/AddPeers", 185 | } 186 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 187 | return srv.(PeerServer).AddPeers(ctx, req.(*Peers)) 188 | } 189 | return interceptor(ctx, in, info, handler) 190 | } 191 | 192 | func _Peer_RemovePeers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 193 | in := new(Peers) 194 | if err := dec(in); err != nil { 195 | return nil, err 196 | } 197 | if interceptor == nil { 198 | return srv.(PeerServer).RemovePeers(ctx, in) 199 | } 200 | info := &grpc.UnaryServerInfo{ 201 | Server: srv, 202 | FullMethod: "/gcgrpc.Peer/RemovePeers", 203 | } 204 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 205 | return srv.(PeerServer).RemovePeers(ctx, req.(*Peers)) 206 | } 207 | return interceptor(ctx, in, info, handler) 208 | } 209 | 210 | func _Peer_SetPeers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 211 | in := new(Peers) 212 | if err := dec(in); err != nil { 213 | return nil, err 214 | } 215 | if interceptor == nil { 216 | return srv.(PeerServer).SetPeers(ctx, in) 217 | } 218 | info := &grpc.UnaryServerInfo{ 219 | Server: srv, 220 | FullMethod: "/gcgrpc.Peer/SetPeers", 221 | } 222 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 223 | return srv.(PeerServer).SetPeers(ctx, req.(*Peers)) 224 | } 225 | return interceptor(ctx, in, info, handler) 226 | } 227 | 228 | var _Peer_serviceDesc = grpc.ServiceDesc{ 229 | ServiceName: "gcgrpc.Peer", 230 | HandlerType: (*PeerServer)(nil), 231 | Methods: []grpc.MethodDesc{ 232 | { 233 | MethodName: "Retrieve", 234 | Handler: _Peer_Retrieve_Handler, 235 | }, 236 | { 237 | MethodName: "AddPeers", 238 | Handler: _Peer_AddPeers_Handler, 239 | }, 240 | { 241 | MethodName: "RemovePeers", 242 | Handler: _Peer_RemovePeers_Handler, 243 | }, 244 | { 245 | MethodName: "SetPeers", 246 | Handler: _Peer_SetPeers_Handler, 247 | }, 248 | }, 249 | Streams: []grpc.StreamDesc{}, 250 | Metadata: fileDescriptor0, 251 | } 252 | 253 | func init() { proto.RegisterFile("gcgrpc.proto", fileDescriptor0) } 254 | 255 | var fileDescriptor0 = []byte{ 256 | // 224 bytes of a gzipped FileDescriptorProto 257 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x4f, 0x4e, 0x2f, 258 | 0x2a, 0x48, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x2c, 0xb9, 0xf8, 259 | 0x83, 0x52, 0x4b, 0x8a, 0x32, 0x53, 0xcb, 0x52, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 260 | 0x44, 0xb8, 0x58, 0xd3, 0x8b, 0xf2, 0x4b, 0x0b, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x20, 261 | 0x1c, 0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, 0x4a, 0x09, 0x26, 0xb0, 0x18, 0x88, 0xa9, 0xa4, 0xc1, 262 | 0x25, 0x80, 0xd0, 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x0a, 0xd2, 0x5b, 0x96, 0x98, 0x53, 0x9a, 263 | 0x0a, 0xd6, 0xcb, 0x13, 0x04, 0xe1, 0x28, 0x29, 0x73, 0xb1, 0x06, 0xa4, 0xa6, 0x16, 0x15, 0x0b, 264 | 0x49, 0x71, 0x71, 0x14, 0x00, 0x19, 0x8e, 0x29, 0x29, 0x45, 0x40, 0x15, 0xcc, 0x40, 0x93, 0xe0, 265 | 0x7c, 0x25, 0x56, 0x2e, 0x66, 0xc7, 0xe4, 0x6c, 0xa3, 0x13, 0x8c, 0x5c, 0x2c, 0x20, 0xc5, 0x42, 266 | 0xf6, 0x5c, 0x1c, 0x30, 0xe3, 0x85, 0xc4, 0xf5, 0xa0, 0x8e, 0x47, 0x73, 0xab, 0x94, 0x04, 0xa6, 267 | 0x04, 0xc4, 0x25, 0x4a, 0x0c, 0x42, 0x1a, 0x5c, 0x1c, 0x40, 0x83, 0x21, 0x16, 0xf3, 0xc2, 0xd4, 268 | 0x81, 0xb9, 0x52, 0xdc, 0x30, 0x2e, 0xd0, 0x46, 0xa0, 0x4a, 0x6d, 0x2e, 0xee, 0xa0, 0xd4, 0xdc, 269 | 0xfc, 0xb2, 0x54, 0x62, 0x14, 0x03, 0x8d, 0x0d, 0x4e, 0x2d, 0x21, 0x42, 0x65, 0x12, 0x1b, 0x38, 270 | 0xa8, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc8, 0x5b, 0x48, 0xe6, 0x7a, 0x01, 0x00, 0x00, 271 | } 272 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------