aliveNode is invoked by the network layer when we get a message about a live node.
(a *alive, notify chan struct{}, bootstrap bool)
| 941 | // aliveNode is invoked by the network layer when we get a message about a |
| 942 | // live node. |
| 943 | func (m *Memberlist) aliveNode(a *alive, notify chan struct{}, bootstrap bool) { |
| 944 | m.nodeLock.Lock() |
| 945 | defer m.nodeLock.Unlock() |
| 946 | state, ok := m.nodeMap[a.Node] |
| 947 | |
| 948 | // It is possible that during a Leave(), there is already an aliveMsg |
| 949 | // in-queue to be processed but blocked by the locks above. If we let |
| 950 | // that aliveMsg process, it'll cause us to re-join the cluster. This |
| 951 | // ensures that we don't. |
| 952 | if m.hasLeft() && a.Node == m.config.Name { |
| 953 | return |
| 954 | } |
| 955 | |
| 956 | if len(a.Vsn) >= 3 { |
| 957 | pMin := a.Vsn[0] |
| 958 | pMax := a.Vsn[1] |
| 959 | pCur := a.Vsn[2] |
| 960 | if pMin == 0 || pMax == 0 || pMin > pMax { |
| 961 | m.logger.Printf("[WARN] memberlist: Ignoring an alive message for '%s' (%v:%d) because protocol version(s) are wrong: %d <= %d <= %d should be >0", a.Node, net.IP(a.Addr), a.Port, pMin, pCur, pMax) |
| 962 | return |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | // Invoke the Alive delegate if any. This can be used to filter out |
| 967 | // alive messages based on custom logic. For example, using a cluster name. |
| 968 | // Using a merge delegate is not enough, as it is possible for passive |
| 969 | // cluster merging to still occur. |
| 970 | if m.config.Alive != nil { |
| 971 | if len(a.Vsn) < 6 { |
| 972 | m.logger.Printf("[WARN] memberlist: ignoring alive message for '%s' (%v:%d) because Vsn is not present", |
| 973 | a.Node, net.IP(a.Addr), a.Port) |
| 974 | return |
| 975 | } |
| 976 | node := &Node{ |
| 977 | Name: a.Node, |
| 978 | Addr: a.Addr, |
| 979 | Port: a.Port, |
| 980 | Meta: a.Meta, |
| 981 | PMin: a.Vsn[0], |
| 982 | PMax: a.Vsn[1], |
| 983 | PCur: a.Vsn[2], |
| 984 | DMin: a.Vsn[3], |
| 985 | DMax: a.Vsn[4], |
| 986 | DCur: a.Vsn[5], |
| 987 | } |
| 988 | if err := m.config.Alive.NotifyAlive(node); err != nil { |
| 989 | m.logger.Printf("[WARN] memberlist: ignoring alive message for '%s': %s", |
| 990 | a.Node, err) |
| 991 | return |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | // Check if we've never seen this node before, and if not, then |
| 996 | // store this node in our node map. |
| 997 | var updatesNode bool |
| 998 | if !ok { |
| 999 | errCon := m.config.IPAllowed(a.Addr) |
| 1000 | if errCon != nil { |