Skip to content

Commit

Permalink
Merge pull request #52 from kqzh/update_version_3.7.0
Browse files Browse the repository at this point in the history
fix: remove handleshakekey
  • Loading branch information
kqzh authored Jan 29, 2024
2 parents bc1087e + cd4832f commit f6c6e3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
3 changes: 1 addition & 2 deletions cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var (
caPath = flag.String("ca_path", "/usr/local/certs/ca.crt", "path to CA file")
enableSSL = flag.Bool("enable_ssl", false, "Enable SSL for agent")
insecureSkipVerify = flag.Bool("insecure_skip_verify", false, "Skip server side cert verification")
handshakeKey = flag.String("handshake_key", "3.0.0", "Specify the key for handshake with nebula")
)

func main() {
Expand Down Expand Up @@ -94,7 +93,7 @@ func main() {
tlsConfig.InsecureSkipVerify = *insecureSkipVerify
}

metaCfg, err := clients.NewMetaConfig(*agent, *meta, GitInfoSHA, *handshakeKey, *hbs, tlsConfig)
metaCfg, err := clients.NewMetaConfig(*agent, *meta, GitInfoSHA, *hbs, tlsConfig)
if err != nil {
log.WithError(err).Fatalf("Failed to create meta config.")
}
Expand Down
44 changes: 19 additions & 25 deletions internal/clients/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ const (
)

type MetaConfig struct {
GitInfoSHA string
HBInterval int
MetaAddr *nebula.HostAddr // meta service address to connect
AgentAddr *nebula.HostAddr // info to be reported to the meta service
TLSConfig *tls.Config
HandShakeKey string
GitInfoSHA string
HBInterval int
MetaAddr *nebula.HostAddr // meta service address to connect
AgentAddr *nebula.HostAddr // info to be reported to the meta service
TLSConfig *tls.Config
}

func NewMetaConfig(agentAddr, metaAddr, gitSHA, handshakeKey string, hbInterval int, tlsConfig *tls.Config) (*MetaConfig, error) {
func NewMetaConfig(agentAddr, metaAddr, gitSHA string, hbInterval int, tlsConfig *tls.Config) (*MetaConfig, error) {
cfg := &MetaConfig{
GitInfoSHA: gitSHA,
HBInterval: hbInterval,
TLSConfig: tlsConfig,
HandShakeKey: handshakeKey,
GitInfoSHA: gitSHA,
HBInterval: hbInterval,
TLSConfig: tlsConfig,
}
var err error

Expand Down Expand Up @@ -63,7 +61,7 @@ func NewMeta(config *MetaConfig) (*NebulaMeta, error) {
}
var err error

if m.client, err = connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey); err != nil {
if m.client, err = connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig); err != nil {
return nil, err
}

Expand All @@ -75,7 +73,7 @@ func NewMeta(config *MetaConfig) (*NebulaMeta, error) {
// We will reconnect when:
// 1. the meta service leader changed
// 2. get individual info from individual meta service, such as dir info
func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config, handshakeKey string) (*meta.MetaServiceClient, error) {
func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config) (*meta.MetaServiceClient, error) {
addr := utils.StringifyAddr(metaAddr)
log.WithField("meta address", addr).Info("try to connect meta service")

Expand Down Expand Up @@ -106,7 +104,7 @@ func connect(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config, handsh
return nil, err
}

req := newVerifyClientVersionReq(agentAddr, handshakeKey)
req := newVerifyClientVersionReq(agentAddr)
resp, err := client.VerifyClientVersion(req)
if err != nil || resp.Code != nebula.ErrorCode_SUCCEEDED {
if err == nil {
Expand Down Expand Up @@ -152,7 +150,7 @@ func (m *NebulaMeta) heartbeat() error {
for {
resp, err := m.client.AgentHeartbeat(req)
if err != nil {
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig)
if err != nil {
return err
}
Expand All @@ -178,7 +176,7 @@ func (m *NebulaMeta) heartbeat() error {
return LeaderNotFoundError
}
m.config.MetaAddr = resp.GetLeader()
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
c, err := connect(m.config.MetaAddr, m.config.AgentAddr, m.config.TLSConfig)
if err != nil {
return err
}
Expand All @@ -197,10 +195,10 @@ func (m *NebulaMeta) heartbeat() error {

// getMetaDirInfo get individual meta dir info of given meta service.
// Because follower meta service could not report its dir info to the leader one.
func getMetaDirInfo(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config, handshakeKey string) (*nebula.DirInfo, error) {
func getMetaDirInfo(metaAddr, agentAddr *nebula.HostAddr, tlsConfig *tls.Config) (*nebula.DirInfo, error) {
log.WithField("addr", utils.StringifyAddr(metaAddr)).
Debugf("Try to get dir info from meta service: %s\n", utils.StringifyAddr(metaAddr))
c, err := connect(metaAddr, agentAddr, tlsConfig, handshakeKey)
c, err := connect(metaAddr, agentAddr, tlsConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -234,7 +232,7 @@ func (m *NebulaMeta) refreshInfo(services []*meta.ServiceInfo) error {
for _, s := range services {
k := utils.StringifyAddr(s.GetAddr())
if s.GetRole() == meta.HostRole_META {
d, err := getMetaDirInfo(s.Addr, m.config.AgentAddr, m.config.TLSConfig, m.config.HandShakeKey)
d, err := getMetaDirInfo(s.Addr, m.config.AgentAddr, m.config.TLSConfig)
if err != nil {
return fmt.Errorf("get meta dir for %s failed: %w", k, err)
}
Expand All @@ -250,13 +248,9 @@ func (m *NebulaMeta) refreshInfo(services []*meta.ServiceInfo) error {
return nil
}

func newVerifyClientVersionReq(agentAddr *nebula.HostAddr, handshakeKey string) *meta.VerifyClientVersionReq {
if handshakeKey == "" {
handshakeKey = nebula.Version
}

func newVerifyClientVersionReq(agentAddr *nebula.HostAddr) *meta.VerifyClientVersionReq {
return &meta.VerifyClientVersionReq{
ClientVersion: []byte(handshakeKey),
ClientVersion: []byte(nebula.Version),
Host: agentAddr,
}
}

0 comments on commit f6c6e3a

Please sign in to comment.