merge redis-over-wg
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
commit
f845269a5a
13 changed files with 522 additions and 204 deletions
|
@ -32,6 +32,8 @@ type Master struct {
|
|||
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
GRPCAddress string `protobuf:"bytes,2,opt,name=grpc_address,json=grpcAddress,proto3" json:"grpc_address,omitempty"`
|
||||
RedisURL string `protobuf:"bytes,3,opt,name=redis_url,json=redisUrl,proto3" json:"redis_url,omitempty"`
|
||||
GatewayIP string `protobuf:"bytes,4,opt,name=gateway_ip,json=gatewayIp,proto3" json:"gateway_ip,omitempty"`
|
||||
Peers []*Peer `protobuf:"bytes,5,rep,name=peers,proto3" json:"peers,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -82,9 +84,27 @@ func (m *Master) GetRedisURL() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (m *Master) GetGatewayIP() string {
|
||||
if m != nil {
|
||||
return m.GatewayIP
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Master) GetPeers() []*Peer {
|
||||
if m != nil {
|
||||
return m.Peers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type JoinRequest struct {
|
||||
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
ClusterKey string `protobuf:"bytes,2,opt,name=cluster_key,json=clusterKey,proto3" json:"cluster_key,omitempty"`
|
||||
GRPCAddress string `protobuf:"bytes,3,opt,name=grpc_address,json=grpcAddress,proto3" json:"grpc_address,omitempty"`
|
||||
EndpointIP string `protobuf:"bytes,4,opt,name=endpoint_ip,json=endpointIp,proto3" json:"endpoint_ip,omitempty"`
|
||||
EndpointPort uint64 `protobuf:"varint,5,opt,name=endpoint_port,json=endpointPort,proto3" json:"endpoint_port,omitempty"`
|
||||
InterfaceName string `protobuf:"bytes,6,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -128,8 +148,38 @@ func (m *JoinRequest) GetClusterKey() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (m *JoinRequest) GetGRPCAddress() string {
|
||||
if m != nil {
|
||||
return m.GRPCAddress
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *JoinRequest) GetEndpointIP() string {
|
||||
if m != nil {
|
||||
return m.EndpointIP
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *JoinRequest) GetEndpointPort() uint64 {
|
||||
if m != nil {
|
||||
return m.EndpointPort
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *JoinRequest) GetInterfaceName() string {
|
||||
if m != nil {
|
||||
return m.InterfaceName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type JoinResponse struct {
|
||||
Master *Master `protobuf:"bytes,1,opt,name=master,proto3" json:"master,omitempty"`
|
||||
Node *Node `protobuf:"bytes,2,opt,name=node,proto3" json:"node,omitempty"`
|
||||
Peers []*Peer `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -166,6 +216,20 @@ func (m *JoinResponse) GetMaster() *Master {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *JoinResponse) GetNode() *Node {
|
||||
if m != nil {
|
||||
return m.Node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *JoinResponse) GetPeers() []*Peer {
|
||||
if m != nil {
|
||||
return m.Peers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConnectRequest struct {
|
||||
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
|
@ -464,6 +528,7 @@ type Node struct {
|
|||
EndpointPort uint64 `protobuf:"varint,5,opt,name=endpoint_port,json=endpointPort,proto3" json:"endpoint_port,omitempty"`
|
||||
GatewayIP string `protobuf:"bytes,6,opt,name=gateway_ip,json=gatewayIp,proto3" json:"gateway_ip,omitempty"`
|
||||
Updated time.Time `protobuf:"bytes,7,opt,name=updated,proto3,stdtime" json:"updated"`
|
||||
InterfaceName string `protobuf:"bytes,8,opt,name=interface_name,json=interfaceName,proto3" json:"interface_name,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
@ -542,6 +607,13 @@ func (m *Node) GetUpdated() time.Time {
|
|||
return time.Time{}
|
||||
}
|
||||
|
||||
func (m *Node) GetInterfaceName() string {
|
||||
if m != nil {
|
||||
return m.InterfaceName
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type NodesRequest struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
|
@ -967,71 +1039,75 @@ func init() {
|
|||
}
|
||||
|
||||
var fileDescriptor_b6184fc395da86b1 = []byte{
|
||||
// 1014 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x5d, 0x6f, 0xe3, 0x44,
|
||||
0x17, 0x7e, 0x9d, 0xef, 0x1c, 0x27, 0x8d, 0x34, 0x5a, 0xf5, 0xf5, 0x06, 0x21, 0x17, 0xef, 0x05,
|
||||
0x59, 0xb4, 0xb2, 0x9b, 0x00, 0xe2, 0x4b, 0x8b, 0x68, 0x9a, 0xdd, 0xc5, 0x14, 0xaa, 0xec, 0x2c,
|
||||
0x7b, 0x83, 0x56, 0x0a, 0x6e, 0x3c, 0xa4, 0x6e, 0x9d, 0xcc, 0x60, 0x4f, 0x5a, 0x85, 0x1b, 0x6e,
|
||||
0xb9, 0xe4, 0xff, 0x20, 0x71, 0x0d, 0xff, 0x80, 0xab, 0x20, 0xe5, 0x97, 0xa0, 0x19, 0x8f, 0x4d,
|
||||
0xd2, 0x36, 0xaa, 0xbb, 0xec, 0x5d, 0xe6, 0xcc, 0x79, 0xce, 0x39, 0x7e, 0xce, 0x73, 0x8e, 0x1d,
|
||||
0xf8, 0x78, 0x12, 0xf0, 0xd3, 0xf9, 0x89, 0x3d, 0xa6, 0x53, 0x27, 0xe6, 0x24, 0x0c, 0xbd, 0x88,
|
||||
0x45, 0xf4, 0x8c, 0x8c, 0xb9, 0x73, 0x4a, 0x82, 0xa9, 0xef, 0x85, 0xa1, 0xe3, 0xb1, 0xc0, 0xb9,
|
||||
0xe8, 0x66, 0x67, 0x9b, 0x45, 0x94, 0x53, 0xf4, 0x4e, 0x40, 0xed, 0x4d, 0x84, 0x9d, 0x79, 0x78,
|
||||
0x2c, 0xb0, 0x2f, 0xba, 0xed, 0x7b, 0x13, 0x3a, 0xa1, 0xd2, 0xdb, 0x11, 0xbf, 0x12, 0x60, 0xfb,
|
||||
0xad, 0x09, 0xa5, 0x93, 0x90, 0x38, 0xf2, 0x74, 0x32, 0xff, 0xc1, 0x21, 0x53, 0xc6, 0x17, 0xea,
|
||||
0xd2, 0xbc, 0x7a, 0xc9, 0x83, 0x29, 0x89, 0xb9, 0x37, 0x65, 0x89, 0x83, 0xf5, 0x33, 0x54, 0xbe,
|
||||
0xf1, 0x62, 0x4e, 0x22, 0xb4, 0x0b, 0x85, 0xc0, 0x37, 0xb4, 0x3d, 0xad, 0x53, 0xef, 0x57, 0x56,
|
||||
0x4b, 0xb3, 0xe0, 0x0e, 0x70, 0x21, 0xf0, 0x51, 0x0f, 0x1a, 0x93, 0x88, 0x8d, 0x47, 0x9e, 0xef,
|
||||
0x47, 0x24, 0x8e, 0x8d, 0x82, 0xf4, 0x68, 0xad, 0x96, 0xa6, 0xfe, 0x0c, 0x0f, 0x0f, 0x0f, 0x12,
|
||||
0x33, 0xd6, 0x85, 0x93, 0x3a, 0xa0, 0x87, 0x50, 0x8f, 0x88, 0x1f, 0xc4, 0xa3, 0x79, 0x14, 0x1a,
|
||||
0x45, 0x09, 0x68, 0xac, 0x96, 0x66, 0x0d, 0x0b, 0xe3, 0x4b, 0xfc, 0x35, 0xae, 0xc9, 0xeb, 0x97,
|
||||
0x51, 0x68, 0x3d, 0x05, 0xfd, 0x2b, 0x1a, 0xcc, 0x30, 0xf9, 0x71, 0x4e, 0x62, 0xbe, 0xb5, 0x0a,
|
||||
0x13, 0xf4, 0x71, 0x38, 0x17, 0x85, 0x8e, 0xce, 0xc9, 0x22, 0x29, 0x02, 0x83, 0x32, 0x1d, 0x91,
|
||||
0x85, 0xf5, 0x1c, 0x1a, 0x49, 0x9c, 0x98, 0xd1, 0x59, 0x4c, 0xd0, 0x01, 0x54, 0xa6, 0xf2, 0xc1,
|
||||
0x64, 0x30, 0xbd, 0xf7, 0xd0, 0xbe, 0x95, 0x60, 0x3b, 0x61, 0x02, 0x2b, 0xa0, 0xd5, 0x81, 0x9d,
|
||||
0x43, 0x3a, 0x9b, 0x91, 0x31, 0xbf, 0xa5, 0x3a, 0xeb, 0x2f, 0x0d, 0x5a, 0x99, 0xab, 0x2a, 0xe0,
|
||||
0x39, 0x54, 0xcf, 0xc9, 0x82, 0x79, 0x41, 0x5a, 0xc1, 0x7b, 0x39, 0x2a, 0x38, 0x22, 0x8b, 0xa1,
|
||||
0x17, 0x44, 0x7d, 0x7d, 0xb5, 0x34, 0xab, 0xea, 0x80, 0xd3, 0x38, 0xc8, 0x80, 0xea, 0x46, 0x17,
|
||||
0x70, 0x7a, 0x44, 0x8f, 0xa1, 0xcc, 0x08, 0x89, 0x62, 0xa3, 0xb8, 0x57, 0xec, 0xe8, 0xbd, 0x77,
|
||||
0x73, 0xa4, 0x1a, 0x12, 0x12, 0xe1, 0x04, 0x85, 0xee, 0x43, 0xd1, 0x9f, 0xc5, 0x46, 0x69, 0xaf,
|
||||
0xd8, 0xa9, 0xf7, 0xab, 0xab, 0xa5, 0x59, 0x1c, 0x1c, 0xbf, 0xc0, 0xc2, 0x66, 0xd9, 0x70, 0xef,
|
||||
0x60, 0xce, 0x4f, 0x69, 0x14, 0xfc, 0x44, 0x24, 0xe4, 0x16, 0x2a, 0xf6, 0x61, 0x77, 0x40, 0xbc,
|
||||
0xbb, 0x20, 0x0c, 0xd8, 0xcd, 0x32, 0xf8, 0x02, 0x10, 0x2b, 0x84, 0xf5, 0x01, 0xfc, 0xff, 0xda,
|
||||
0x8d, 0x62, 0xf7, 0x3e, 0x14, 0x03, 0x3f, 0x36, 0xb4, 0x7f, 0x2b, 0x76, 0x07, 0x31, 0x16, 0x36,
|
||||
0xcb, 0x85, 0x94, 0x39, 0xa1, 0x1a, 0x16, 0x05, 0x17, 0x1e, 0x27, 0x52, 0x35, 0x5a, 0xa2, 0x1a,
|
||||
0x65, 0x3a, 0x22, 0x0b, 0xf4, 0x36, 0x00, 0x9b, 0x9f, 0x84, 0xc1, 0x78, 0x4d, 0x55, 0xf5, 0xc4,
|
||||
0x22, 0x44, 0xf5, 0x67, 0x01, 0x4a, 0xc7, 0xd4, 0x27, 0x5b, 0x65, 0x89, 0xa0, 0x24, 0x5a, 0xa0,
|
||||
0x90, 0xf2, 0xf7, 0x7a, 0xe3, 0x8b, 0x6f, 0xa8, 0xf1, 0x0e, 0xe8, 0x64, 0xe6, 0x33, 0x1a, 0xcc,
|
||||
0xf8, 0x28, 0x60, 0x46, 0x49, 0xd6, 0xb1, 0xb3, 0x5a, 0x9a, 0xf0, 0x44, 0x99, 0xdd, 0x21, 0x86,
|
||||
0xd4, 0xc5, 0x65, 0xe8, 0x01, 0x34, 0x33, 0x00, 0xa3, 0x11, 0x37, 0xca, 0x7b, 0x5a, 0xa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, 0x2e, 0x7b, 0xc0, 0xee, 0x1d, 0x10,
|
||||
0x2a, 0xdd, 0x2b, 0xd0, 0xd7, 0x66, 0x12, 0x7d, 0x98, 0x47, 0x6d, 0xd7, 0x66, 0x78, 0x6b, 0x03,
|
||||
0x5f, 0x81, 0xbe, 0x36, 0x9c, 0xb9, 0xa2, 0x5f, 0x1f, 0xe6, 0xad, 0xd1, 0xcf, 0xa0, 0x2c, 0x5f,
|
||||
0x04, 0xc8, 0xc9, 0xb9, 0xf1, 0x33, 0xa2, 0xf6, 0xf3, 0x03, 0x14, 0x4f, 0x67, 0x50, 0x4e, 0xf4,
|
||||
0xe7, 0xe4, 0x5c, 0x9e, 0x77, 0xca, 0xb5, 0xa1, 0xb5, 0xbe, 0xfd, 0xdd, 0xa3, 0xdc, 0xff, 0x06,
|
||||
0x3e, 0xbb, 0xe8, 0x9e, 0x54, 0x24, 0x2f, 0xef, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0xcd, 0x85,
|
||||
0x12, 0x11, 0x44, 0x0c, 0x00, 0x00,
|
||||
// 1082 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcf, 0x6f, 0xe3, 0x44,
|
||||
0x14, 0xc6, 0xf9, 0x9d, 0x97, 0xa6, 0x95, 0x46, 0xab, 0xe2, 0x0d, 0x42, 0x2e, 0x59, 0x21, 0xb2,
|
||||
0x68, 0x65, 0xb7, 0x05, 0xc4, 0x8f, 0xd5, 0x22, 0xda, 0x66, 0x59, 0x4c, 0xa1, 0x0a, 0xb3, 0xec,
|
||||
0x05, 0xad, 0x14, 0xdc, 0xf8, 0x6d, 0xea, 0xd6, 0xf1, 0x0c, 0xf6, 0xa4, 0x55, 0xf8, 0x0b, 0x38,
|
||||
0xf2, 0xff, 0x20, 0x71, 0xe6, 0xc2, 0x9d, 0x53, 0x90, 0x72, 0xe6, 0xc0, 0x8d,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0x2e, 0x36, 0x8f, 0x48, 0x0b, 0x6a, 0x69, 0xa7, 0x92, 0x66, 0xd3, 0xec, 0x2c,
|
||||
0x09, 0x5a, 0x58, 0x92, 0x03, 0x68, 0x2e, 0xae, 0x46, 0xa6, 0x05, 0xda, 0xad, 0x54, 0xef, 0x4b,
|
||||
0x28, 0x53, 0x36, 0x16, 0x48, 0xee, 0x41, 0x55, 0x52, 0xd6, 0xcf, 0x58, 0x82, 0xd9, 0xd4, 0xa8,
|
||||
0x48, 0x2e, 0xed, 0x2e, 0xad, 0xc8, 0x2b, 0xdb, 0x95, 0x92, 0x14, 0xa0, 0x38, 0x63, 0xe1, 0x49,
|
||||
0x2a, 0x49, 0xea, 0xd8, 0x7e, 0x0a, 0x64, 0x2f, 0x44, 0x47, 0x60, 0x1c, 0x2d, 0x15, 0x81, 0x97,
|
||||
0x0c, 0x6a, 0x02, 0xe9, 0xa2, 0x8f, 0x17, 0x82, 0xce, 0xf9, 0x6b, 0x8b, 0xfe, 0x6b, 0xd0, 0x8c,
|
||||
0x3d, 0x33, 0xb6, 0x28, 0xac, 0xa6, 0x06, 0x45, 0xd7, 0x17, 0x50, 0x09, 0x63, 0x8b, 0xe2, 0xab,
|
||||
0x93, 0x83, 0xaf, 0x24, 0xbb, 0xc2, 0x6d, 0xff, 0x56, 0x83, 0xda, 0x57, 0xca, 0x83, 0x70, 0xa8,
|
||||
0xaa, 0x97, 0x80, 0x6c, 0xe5, 0x88, 0xb4, 0xf8, 0xc0, 0xb4, 0xb6, 0x6f, 0x02, 0x51, 0x05, 0xfc,
|
||||
0x08, 0xcd, 0x05, 0x85, 0x26, 0x1f, 0xe7, 0x08, 0x72, 0x95, 0xa6, 0xb7, 0xd6, 0x2f, 0x6d, 0xf4,
|
||||
0x63, 0xf9, 0xa1, 0x47, 0x5c, 0x58, 0xbb, 0xa0, 0xe9, 0xe4, 0xd3, 0x1c, 0x39, 0xae, 0x7e, 0x07,
|
||||
0x96, 0x66, 0xf9, 0x45, 0x83, 0xb5, 0x0b, 0x72, 0x9f, 0x2b, 0xcd, 0xd5, 0x8f, 0x47, 0xeb, 0xb3,
|
||||
0xdb, 0x40, 0x15, 0xa5, 0x43, 0x28, 0xc9, 0x0f, 0x19, 0x62, 0xe6, 0x88, 0x31, 0xf7, 0xad, 0xd7,
|
||||
0xb2, 0x72, 0xfb, 0xab, 0x44, 0x23, 0xa8, 0x24, 0xe3, 0x48, 0x36, 0xf3, 0x8e, 0x5d, 0x56, 0xe0,
|
||||
0xd6, 0x0d, 0x10, 0x2a, 0xdd, 0x73, 0x68, 0xcc, 0xed, 0x24, 0xf9, 0x28, 0xcf, 0xb4, 0x5d, 0xda,
|
||||
0xe1, 0xa5, 0x0d, 0x7c, 0x0e, 0x8d, 0xb9, 0xe5, 0xcc, 0x15, 0xfd, 0xf2, 0x32, 0x2f, 0x8d, 0x7e,
|
||||
0x0c, 0xe5, 0xf8, 0x21, 0x20, 0x56, 0x4e, 0xc5, 0xcf, 0x88, 0xda, 0xcc, 0x0f, 0x50, 0x3c, 0x1d,
|
||||
0x43, 0x39, 0x99, 0x3f, 0x2b, 0xa7, 0x78, 0xde, 0x28, 0xd7, 0xc2, 0xac, 0xed, 0x9a, 0x3f, 0x3c,
|
||||
0xc8, 0xfd, 0x1f, 0xdd, 0xc3, 0xd3, 0xad, 0xc3, 0x4a, 0xcc, 0xcb, 0x07, 0xff, 0x07, 0x00, 0x00,
|
||||
0xff, 0xff, 0xdf, 0x73, 0xc4, 0x68, 0x08, 0x0e, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
|
|
@ -25,15 +25,23 @@ message Master {
|
|||
string id = 1 [(gogoproto.customname) = "ID"];
|
||||
string grpc_address = 2 [(gogoproto.customname) = "GRPCAddress"];
|
||||
string redis_url = 3 [(gogoproto.customname) = "RedisURL"];
|
||||
string gateway_ip = 4 [(gogoproto.customname) = "GatewayIP"];
|
||||
repeated Peer peers = 5;
|
||||
}
|
||||
|
||||
message JoinRequest {
|
||||
string id = 1 [(gogoproto.customname) = "ID"];
|
||||
string cluster_key = 2;
|
||||
string grpc_address = 3 [(gogoproto.customname) = "GRPCAddress"];
|
||||
string endpoint_ip = 4 [(gogoproto.customname) = "EndpointIP"];
|
||||
uint64 endpoint_port = 5;
|
||||
string interface_name = 6;
|
||||
}
|
||||
|
||||
message JoinResponse {
|
||||
Master master = 1;
|
||||
Node node = 2;
|
||||
repeated Peer peers = 3;
|
||||
}
|
||||
|
||||
message ConnectRequest {
|
||||
|
@ -74,6 +82,7 @@ message Node {
|
|||
uint64 endpoint_port = 5;
|
||||
string gateway_ip = 6 [(gogoproto.customname) = "GatewayIP"];
|
||||
google.protobuf.Timestamp updated = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||
string interface_name = 8;
|
||||
}
|
||||
|
||||
message NodesRequest {}
|
||||
|
|
|
@ -28,15 +28,7 @@ import (
|
|||
)
|
||||
|
||||
// Join attempts to connect to the peer and returns the master info
|
||||
func (c *Client) Join(key string) (*v1.Master, error) {
|
||||
func (c *Client) Join(req *v1.JoinRequest) (*v1.JoinResponse, error) {
|
||||
ctx := context.Background()
|
||||
resp, err := c.heimdallClient.Join(ctx, &v1.JoinRequest{
|
||||
ID: c.id,
|
||||
ClusterKey: key,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Master, nil
|
||||
return c.heimdallClient.Join(ctx, req)
|
||||
}
|
||||
|
|
|
@ -72,12 +72,6 @@ func main() {
|
|||
Value: "redis://127.0.0.1:6379/0",
|
||||
EnvVar: "HEIMDALL_REDIS_URL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "advertise-redis-url, p",
|
||||
Usage: "advertise uri for peers",
|
||||
Value: fmt.Sprintf("redis://%s:6379/0", heimdall.GetIP()),
|
||||
EnvVar: "HEIMDALL_ADVERTISE_REDIS_URL",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "peer",
|
||||
Usage: "grpc address to join a peer",
|
||||
|
|
|
@ -52,7 +52,6 @@ func runServer(cx *cli.Context) error {
|
|||
EndpointPort: cx.Int("endpoint-port"),
|
||||
InterfaceName: cx.String("interface-name"),
|
||||
RedisURL: cx.String("redis-url"),
|
||||
AdvertiseRedisURL: cx.String("advertise-redis-url"),
|
||||
}
|
||||
|
||||
errCh := make(chan error, 1)
|
||||
|
|
|
@ -47,8 +47,6 @@ type Config struct {
|
|||
InterfaceName string
|
||||
// RedisURL is the uri to the redis backend
|
||||
RedisURL string
|
||||
// AdvertiseRedisURL is the uri to the public redis backend
|
||||
AdvertiseRedisURL string
|
||||
// TLSCertificate is the certificate used for grpc communication
|
||||
TLSServerCertificate string
|
||||
// TLSKey is the key used for grpc communication
|
||||
|
|
1
go.mod
1
go.mod
|
@ -6,6 +6,7 @@ require (
|
|||
github.com/certifi/gocertifi v0.0.0-20190905060710-a5e0173ced67 // indirect
|
||||
github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd
|
||||
github.com/crosbymichael/guard v0.0.0-20190716141324-5c2daadf8067 // indirect
|
||||
github.com/digineo/go-ping v1.0.0
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/getsentry/raven-go v0.2.0 // indirect
|
||||
github.com/gogo/googleapis v1.3.0
|
||||
|
|
16
go.sum
16
go.sum
|
@ -19,9 +19,16 @@ github.com/crosbymichael/guard v0.0.0-20190716141324-5c2daadf8067/go.mod h1:+l2f
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0 h1:OT/LKmj81wMymnWXaKaKBR9n1vPlu+GC0VVKaZP6kzs=
|
||||
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0/go.mod h1:DmqdumeAKGQNU5E8MN0ruT5ZGx8l/WbAsMbXCXcSEts=
|
||||
github.com/digineo/go-ping v1.0.0 h1:gOuD3YzkIcW/0Y2IAe27bsMKtpfNZdoX1Rnc1RGYOSI=
|
||||
github.com/digineo/go-ping v1.0.0/go.mod h1:YLDBnHoAygacawa2aubI4vXhZ4do5f62oJSvRiJVEjw=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/ehazlett/ttlcache v0.0.0-20190820213212-4400e3aef9f0/go.mod h1:D7IiYXsX2n2xixWvFTxGeZucCvvNtI14ikLj6L9Kp9E=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell v1.1.1/go.mod h1:K1udHkiR3cOtlpKG5tZPD5XxrF7v2y7lDq7Whcj+xkQ=
|
||||
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
|
||||
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
|
@ -61,6 +68,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi
|
|||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
|
@ -89,6 +100,7 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
|
|||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE=
|
||||
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
|
||||
github.com/rivo/tview v0.0.0-20181226202439-36893a669792/go.mod h1:J4W+hErFfITUbyFAEXizpmkuxX7ZN56dopxHB4XQhMw=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
|
@ -115,6 +127,7 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
|
|||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
|
||||
|
@ -125,6 +138,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -144,9 +158,11 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
|
|||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
|
||||
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
|
||||
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
|
|
@ -60,7 +60,35 @@ func (s *Server) Join(ctx context.Context, req *v1.JoinRequest) (*v1.JoinRespons
|
|||
return nil, err
|
||||
}
|
||||
|
||||
peers, err := s.getPeers(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.ensureNetworkSubnet(ctx, req.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node, err := s.getNode(ctx, req.ID)
|
||||
if err != nil {
|
||||
if err != redis.ErrNil {
|
||||
return nil, err
|
||||
}
|
||||
n, err := s.createNode(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.updatePeerInfo(ctx, req.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node = n
|
||||
}
|
||||
|
||||
return &v1.JoinResponse{
|
||||
Master: &master,
|
||||
Node: node,
|
||||
Peers: peers,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gomodule/redigo/redis"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type subnetRange struct {
|
||||
|
@ -37,8 +39,9 @@ type subnetRange struct {
|
|||
Subnet *net.IPNet
|
||||
}
|
||||
|
||||
func (s *Server) updateNodeNetwork(ctx context.Context, subnet string) error {
|
||||
if _, err := s.master(ctx, "SET", s.getNodeNetworkKey(s.cfg.ID), subnet); err != nil {
|
||||
func (s *Server) updateNodeNetwork(ctx context.Context, id string, subnet string) error {
|
||||
logrus.Debugf("updating node network: id=%s subnet=%s", id, subnet)
|
||||
if _, err := s.master(ctx, "SET", s.getNodeNetworkKey(id), subnet); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -70,7 +73,7 @@ func (s *Server) getOrAllocatePeerIP(ctx context.Context, id string) (net.IP, *n
|
|||
func (s *Server) getNodeIP(ctx context.Context, id string) (net.IP, *net.IPNet, error) {
|
||||
subnet, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(id)))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, errors.Wrap(err, "error getting node ip")
|
||||
}
|
||||
r, err := parseSubnetRange(subnet)
|
||||
if err != nil {
|
||||
|
|
205
server/node.go
205
server/node.go
|
@ -23,6 +23,7 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -82,22 +83,13 @@ func (s *Server) getNode(ctx context.Context, id string) (*v1.Node, error) {
|
|||
|
||||
func (s *Server) configureNode() error {
|
||||
ctx := context.Background()
|
||||
nodeKeys, err := redis.Strings(s.local(ctx, "KEYS", s.getNodeKey("*")))
|
||||
nodes, err := s.getNodes(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// attempt to connect to existing
|
||||
if len(nodeKeys) > 0 {
|
||||
for _, nodeKey := range nodeKeys {
|
||||
nodeData, err := redis.Bytes(s.local(ctx, "GET", nodeKey))
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
continue
|
||||
}
|
||||
var node v1.Node
|
||||
if err := proto.Unmarshal(nodeData, &node); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(nodes) > 0 {
|
||||
for _, node := range nodes {
|
||||
// ignore self
|
||||
if node.ID == s.cfg.ID {
|
||||
continue
|
||||
|
@ -109,19 +101,41 @@ func (s *Server) configureNode() error {
|
|||
logrus.Warn(err)
|
||||
continue
|
||||
}
|
||||
m, err := c.Join(s.cfg.ClusterKey)
|
||||
r, err := c.Join(&v1.JoinRequest{
|
||||
ID: s.cfg.ID,
|
||||
ClusterKey: s.cfg.ClusterKey,
|
||||
GRPCAddress: s.cfg.GRPCAddress,
|
||||
EndpointIP: s.cfg.EndpointIP,
|
||||
EndpointPort: uint64(s.cfg.EndpointPort),
|
||||
InterfaceName: s.cfg.InterfaceName,
|
||||
})
|
||||
if err != nil {
|
||||
c.Close()
|
||||
logrus.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := s.joinMaster(m); err != nil {
|
||||
// start tunnel
|
||||
if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil {
|
||||
return err
|
||||
}
|
||||
// wait for tunnel to come up
|
||||
logrus.Infof("waiting for master %s", r.Master.ID)
|
||||
if err := s.waitForMaster(ctx, r.Master); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.joinMaster(r.Master); err != nil {
|
||||
c.Close()
|
||||
logrus.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Infof("waiting for redis sync with %s", r.Master.ID)
|
||||
if err := s.waitForRedisSync(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go s.replicaMonitor()
|
||||
|
||||
return nil
|
||||
|
@ -154,6 +168,8 @@ func (s *Server) configureNode() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// TODO: start tunnel
|
||||
|
||||
if err := s.joinMaster(&master); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -163,14 +179,19 @@ func (s *Server) configureNode() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) disableReplica() {
|
||||
s.wpool = getPool(s.cfg.RedisURL)
|
||||
func (s *Server) disableReplica() error {
|
||||
p, err := getPool(s.cfg.RedisURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.wpool = p
|
||||
|
||||
// signal replica monitor to stop if started as a peer
|
||||
close(s.replicaCh)
|
||||
|
||||
// unset peer
|
||||
s.cfg.GRPCPeerAddress = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) replicaMonitor() {
|
||||
|
@ -187,10 +208,12 @@ func (s *Server) replicaMonitor() {
|
|||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
if n.ID != s.cfg.ID {
|
||||
logrus.Debugf("waiting for new master to initialize: %s", n.ID)
|
||||
logrus.Debugf("replica monitor: node=%s", n)
|
||||
if n == nil || n.ID != s.cfg.ID {
|
||||
logrus.Debug("waiting for new master to initialize")
|
||||
continue
|
||||
}
|
||||
logrus.Debugf("replica monitor: configuring node with master %+v", n)
|
||||
if err := s.configureNode(); err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
|
@ -242,12 +265,15 @@ func (s *Server) masterHeartbeat() {
|
|||
func (s *Server) joinMaster(m *v1.Master) error {
|
||||
// configure replica
|
||||
logrus.Infof("configuring node as replica of %+v", m.ID)
|
||||
conn, err := redis.DialURL(s.cfg.RedisURL)
|
||||
pool, err := getPool(s.cfg.RedisURL)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to connect to redis")
|
||||
return err
|
||||
}
|
||||
|
||||
conn := pool.Get()
|
||||
defer conn.Close()
|
||||
|
||||
logrus.Debugf("configuring redis as slave of %s", m.ID)
|
||||
u, err := url.Parse(m.RedisURL)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing master redis url")
|
||||
|
@ -258,27 +284,37 @@ func (s *Server) joinMaster(m *v1.Master) error {
|
|||
if _, err := conn.Do("REPLICAOF", host, port); err != nil {
|
||||
return err
|
||||
}
|
||||
// auth
|
||||
auth, ok := u.User.Password()
|
||||
if ok {
|
||||
if _, err := conn.Do("CONFIG", "SET", "MASTERAUTH", auth); err != nil {
|
||||
return errors.Wrap(err, "error authenticating to redis")
|
||||
}
|
||||
}
|
||||
|
||||
s.wpool = getPool(m.RedisURL)
|
||||
s.wpool, err = getPool(m.RedisURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) updateMasterInfo(ctx context.Context) error {
|
||||
// update master info
|
||||
if _, err := s.master(ctx, "SET", clusterKey, s.cfg.ClusterKey); err != nil {
|
||||
logrus.Error("updateMasterInfo.setClusterKey")
|
||||
return err
|
||||
}
|
||||
// build redis url with gateway ip
|
||||
gatewayIP, _, err := s.getNodeIP(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
logrus.Error("updateMasterInfo.getNodeIP")
|
||||
return err
|
||||
}
|
||||
u, err := url.Parse(s.cfg.RedisURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update master redis url to gateway to serve over wireguard
|
||||
u.Host = fmt.Sprintf("%s:%s", gatewayIP.String(), u.Port())
|
||||
m := &v1.Master{
|
||||
ID: s.cfg.ID,
|
||||
GRPCAddress: s.cfg.AdvertiseGRPCAddress,
|
||||
RedisURL: s.cfg.AdvertiseRedisURL,
|
||||
RedisURL: u.String(),
|
||||
GatewayIP: gatewayIP.String(),
|
||||
}
|
||||
data, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
|
@ -292,48 +328,91 @@ func (s *Server) updateMasterInfo(ctx context.Context) error {
|
|||
if _, err := s.master(ctx, "EXPIRE", masterKey, int(masterHeartbeatInterval.Seconds())); err != nil {
|
||||
return errors.Wrap(err, "error setting expire for master info")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) nodeHeartbeat(ctx context.Context) {
|
||||
func (s *Server) updateNodeInfo(ctx context.Context) {
|
||||
logrus.Debugf("starting node heartbeat: ttl=%s", nodeHeartbeatInterval)
|
||||
t := time.NewTicker(nodeHeartbeatInterval)
|
||||
key := s.getNodeKey(s.cfg.ID)
|
||||
for range t.C {
|
||||
keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
nodeIP, _, err := s.getNodeIP(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
node := &v1.Node{
|
||||
Updated: time.Now(),
|
||||
ID: s.cfg.ID,
|
||||
Addr: s.cfg.GRPCAddress,
|
||||
KeyPair: keyPair,
|
||||
EndpointIP: s.cfg.EndpointIP,
|
||||
EndpointPort: uint64(s.cfg.EndpointPort),
|
||||
GatewayIP: nodeIP.String(),
|
||||
}
|
||||
|
||||
data, err := proto.Marshal(node)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "SET", key, data); err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil {
|
||||
if err := s.updateLocalNodeInfo(ctx); err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) updateLocalNodeInfo(ctx context.Context) error {
|
||||
key := s.getNodeKey(s.cfg.ID)
|
||||
keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting keypair for %s", s.cfg.ID)
|
||||
}
|
||||
nodeIP, _, err := s.getNodeIP(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting node IP for %s", s.cfg.ID)
|
||||
}
|
||||
node := &v1.Node{
|
||||
Updated: time.Now(),
|
||||
ID: s.cfg.ID,
|
||||
Addr: s.cfg.GRPCAddress,
|
||||
KeyPair: keyPair,
|
||||
EndpointIP: s.cfg.EndpointIP,
|
||||
EndpointPort: uint64(s.cfg.EndpointPort),
|
||||
GatewayIP: nodeIP.String(),
|
||||
InterfaceName: s.cfg.InterfaceName,
|
||||
}
|
||||
|
||||
data, err := proto.Marshal(node)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "SET", key, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) createNode(ctx context.Context, req *v1.JoinRequest) (*v1.Node, error) {
|
||||
key := s.getNodeKey(req.ID)
|
||||
keyPair, err := s.getOrCreateKeyPair(ctx, req.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error getting/creating keypair for %s", req.ID)
|
||||
}
|
||||
nodeIP, _, err := s.getNodeIP(ctx, req.ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error getting node ip for %s", req.ID)
|
||||
}
|
||||
node := &v1.Node{
|
||||
Updated: time.Now(),
|
||||
ID: req.ID,
|
||||
Addr: req.GRPCAddress,
|
||||
KeyPair: keyPair,
|
||||
EndpointIP: req.EndpointIP,
|
||||
EndpointPort: uint64(req.EndpointPort),
|
||||
GatewayIP: nodeIP.String(),
|
||||
InterfaceName: req.InterfaceName,
|
||||
}
|
||||
|
||||
data, err := proto.Marshal(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "SET", key, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.master(ctx, "EXPIRE", key, nodeHeartbeatExpiry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return node, nil
|
||||
}
|
||||
|
|
|
@ -69,9 +69,7 @@ func (s *Server) getPeers(ctx context.Context) ([]*v1.Peer, error) {
|
|||
|
||||
func (s *Server) peerUpdater(ctx context.Context) {
|
||||
logrus.Debugf("starting peer config updater: ttl=%s", peerConfigUpdateInterval)
|
||||
|
||||
t := time.NewTicker(peerConfigUpdateInterval)
|
||||
|
||||
for range t.C {
|
||||
uctx, cancel := context.WithTimeout(ctx, peerConfigUpdateInterval)
|
||||
if err := s.updatePeerInfo(uctx, s.cfg.ID); err != nil {
|
||||
|
@ -80,7 +78,21 @@ func (s *Server) peerUpdater(ctx context.Context) {
|
|||
continue
|
||||
}
|
||||
|
||||
if err := s.updatePeerConfig(uctx); err != nil {
|
||||
peers, err := s.getPeers(ctx)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
cancel()
|
||||
continue
|
||||
}
|
||||
|
||||
node, err := s.getNode(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
cancel()
|
||||
continue
|
||||
}
|
||||
|
||||
if err := s.updatePeerConfig(uctx, node, peers); err != nil {
|
||||
logrus.Errorf("updatePeerConfig: %s", err)
|
||||
cancel()
|
||||
continue
|
||||
|
@ -208,47 +220,24 @@ func (s *Server) getPeerInfo(ctx context.Context, id string) (*v1.Peer, error) {
|
|||
return &peer, nil
|
||||
}
|
||||
|
||||
func (s *Server) updatePeerConfig(ctx context.Context) error {
|
||||
peerKeys, err := redis.Strings(s.local(ctx, "KEYS", s.getPeerKey("*")))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var peers []*v1.Peer
|
||||
for _, peerKey := range peerKeys {
|
||||
peerData, err := redis.Bytes(s.local(ctx, "GET", peerKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var p v1.Peer
|
||||
if err := proto.Unmarshal(peerData, &p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) updatePeerConfig(ctx context.Context, node *v1.Node, peers []*v1.Peer) error {
|
||||
var nodePeers []*v1.Peer
|
||||
for _, peer := range peers {
|
||||
// do not add self as a peer
|
||||
if p.ID == s.cfg.ID {
|
||||
if peer.ID == node.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
peers = append(peers, &p)
|
||||
nodePeers = append(nodePeers, peer)
|
||||
}
|
||||
|
||||
keyPair, err := s.getOrCreateKeyPair(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gatewayIP, gatewayNet, err := s.getNodeIP(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
size, _ := gatewayNet.Mask.Size()
|
||||
//size, _ := gatewayNet.Mask.Size()
|
||||
wireguardCfg := &wg.Config{
|
||||
Iface: s.cfg.InterfaceName,
|
||||
PrivateKey: keyPair.PrivateKey,
|
||||
ListenPort: s.cfg.EndpointPort,
|
||||
Address: fmt.Sprintf("%s/%d", gatewayIP.To4().String(), size),
|
||||
Peers: peers,
|
||||
Iface: node.InterfaceName,
|
||||
PrivateKey: node.KeyPair.PrivateKey,
|
||||
ListenPort: int(node.EndpointPort),
|
||||
Address: fmt.Sprintf("%s/%d", node.GatewayIP, 16),
|
||||
Peers: nodePeers,
|
||||
}
|
||||
|
||||
wireguardConfigPath := s.getWireguardConfigPath()
|
||||
|
|
168
server/server.go
168
server/server.go
|
@ -22,14 +22,20 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ping "github.com/digineo/go-ping"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"github.com/gomodule/redigo/redis"
|
||||
|
@ -81,7 +87,10 @@ type Server struct {
|
|||
|
||||
// NewServer returns a new Heimdall server
|
||||
func NewServer(cfg *heimdall.Config) (*Server, error) {
|
||||
pool := getPool(cfg.RedisURL)
|
||||
pool, err := getPool(cfg.RedisURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Server{
|
||||
cfg: cfg,
|
||||
rpool: pool,
|
||||
|
@ -121,13 +130,37 @@ func (s *Server) Run() error {
|
|||
}
|
||||
defer c.Close()
|
||||
|
||||
master, err := c.Join(s.cfg.ClusterKey)
|
||||
r, err := c.Join(&v1.JoinRequest{
|
||||
ID: s.cfg.ID,
|
||||
ClusterKey: s.cfg.ClusterKey,
|
||||
GRPCAddress: s.cfg.GRPCAddress,
|
||||
EndpointIP: s.cfg.EndpointIP,
|
||||
EndpointPort: uint64(s.cfg.EndpointPort),
|
||||
InterfaceName: s.cfg.InterfaceName,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("master info received: %+v", master)
|
||||
if err := s.joinMaster(master); err != nil {
|
||||
logrus.Debugf("master info received: %+v", r)
|
||||
// start tunnel
|
||||
if err := s.updatePeerConfig(ctx, r.Node, r.Peers); err != nil {
|
||||
return errors.Wrap(err, "error updating peer config")
|
||||
}
|
||||
|
||||
// wait for tunnel to come up
|
||||
logrus.Infof("waiting for master %s", r.Master.ID)
|
||||
if err := s.waitForMaster(ctx, r.Master); err != nil {
|
||||
return errors.Wrap(err, "error waiting for master")
|
||||
}
|
||||
|
||||
logrus.Debugf("joining master: %s", r.Master.ID)
|
||||
if err := s.joinMaster(r.Master); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("waiting for redis sync with %s", r.Master.ID)
|
||||
if err := s.waitForRedisSync(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -144,12 +177,17 @@ func (s *Server) Run() error {
|
|||
}
|
||||
|
||||
// ensure node network subnet
|
||||
if err := s.ensureNetworkSubnet(ctx); err != nil {
|
||||
if err := s.ensureNetworkSubnet(ctx, s.cfg.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// initial node update
|
||||
if err := s.updateLocalNodeInfo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// start node heartbeat to update in redis
|
||||
go s.nodeHeartbeat(ctx)
|
||||
go s.updateNodeInfo(ctx)
|
||||
|
||||
// initial peer info update
|
||||
if err := s.updatePeerInfo(ctx, s.cfg.ID); err != nil {
|
||||
|
@ -157,7 +195,15 @@ func (s *Server) Run() error {
|
|||
}
|
||||
|
||||
// initial config update
|
||||
if err := s.updatePeerConfig(ctx); err != nil {
|
||||
node, err := s.getNode(ctx, s.cfg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
peers, err := s.getPeers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.updatePeerConfig(ctx, node, peers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -184,7 +230,7 @@ func (s *Server) Run() error {
|
|||
}
|
||||
}()
|
||||
|
||||
err := <-errCh
|
||||
err = <-errCh
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -194,20 +240,106 @@ func (s *Server) Stop() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getPool(u string) *redis.Pool {
|
||||
func getPool(redisUrl string) (*redis.Pool, error) {
|
||||
pool := redis.NewPool(func() (redis.Conn, error) {
|
||||
conn, err := redis.DialURL(u)
|
||||
conn, err := redis.DialURL(redisUrl)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to connect to redis")
|
||||
}
|
||||
|
||||
u, err := url.Parse(redisUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auth, ok := u.User.Password()
|
||||
if ok {
|
||||
if _, err := conn.Do("CONFIG", "SET", "MASTERAUTH", auth); err != nil {
|
||||
return nil, errors.Wrap(err, "error authenticating to redis")
|
||||
}
|
||||
}
|
||||
return conn, nil
|
||||
}, 10)
|
||||
|
||||
return pool
|
||||
return pool, nil
|
||||
}
|
||||
|
||||
func (s *Server) ensureNetworkSubnet(ctx context.Context) error {
|
||||
network, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(s.cfg.ID)))
|
||||
func (s *Server) waitForMaster(ctx context.Context, m *v1.Master) error {
|
||||
p, err := ping.New("0.0.0.0", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer p.Close()
|
||||
|
||||
doneCh := make(chan time.Duration)
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
ip, err := net.ResolveIPAddr("ip4", m.GatewayIP)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
rtt, err := p.Ping(ip, time.Second*30)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
}
|
||||
doneCh <- rtt
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case rtt := <-doneCh:
|
||||
logrus.Debugf("rtt master ping: %s", rtt)
|
||||
return nil
|
||||
case err := <-errCh:
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) waitForRedisSync(ctx context.Context) error {
|
||||
doneCh := make(chan bool)
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
info, err := redis.String(s.local(ctx, "INFO", "REPLICATION"))
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
b := bytes.NewBufferString(info)
|
||||
s := bufio.NewScanner(b)
|
||||
|
||||
for s.Scan() {
|
||||
v := s.Text()
|
||||
parts := strings.SplitN(v, ":", 2)
|
||||
if parts[0] == "master_link_status" {
|
||||
if parts[1] == "up" {
|
||||
doneCh <- true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-doneCh:
|
||||
return nil
|
||||
case err := <-errCh:
|
||||
return err
|
||||
case <-time.After(nodeHeartbeatInterval):
|
||||
return fmt.Errorf("timeout waiting on sync")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) ensureNetworkSubnet(ctx context.Context, id string) error {
|
||||
network, err := redis.String(s.local(ctx, "GET", s.getNodeNetworkKey(id)))
|
||||
if err != nil {
|
||||
if err != redis.ErrNil {
|
||||
return err
|
||||
|
@ -222,7 +354,7 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debug(nodeNetworkKeys)
|
||||
logrus.Debugf("node networks: %s", nodeNetworkKeys)
|
||||
lookup := map[string]struct{}{}
|
||||
for _, netKey := range nodeNetworkKeys {
|
||||
n, err := redis.String(s.local(ctx, "GET", netKey))
|
||||
|
@ -232,6 +364,8 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error {
|
|||
lookup[n] = struct{}{}
|
||||
}
|
||||
|
||||
logrus.Debugf("lookup: %+v", lookup)
|
||||
|
||||
subnet := r.Subnet
|
||||
size, _ := subnet.Mask.Size()
|
||||
|
||||
|
@ -244,8 +378,8 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error {
|
|||
subnet = n
|
||||
continue
|
||||
}
|
||||
logrus.Debugf("allocated network %s for %s", n.String(), s.cfg.ID)
|
||||
if err := s.updateNodeNetwork(ctx, n.String()); err != nil {
|
||||
logrus.Debugf("allocated network %s for %s", n.String(), id)
|
||||
if err := s.updateNodeNetwork(ctx, id, n.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
|
@ -253,7 +387,7 @@ func (s *Server) ensureNetworkSubnet(ctx context.Context) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
logrus.Debugf("node network: %s", network)
|
||||
logrus.Debugf("node network for %s: %s", id, network)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue