Exemple #1
0
func (svr *lmiServer) processComputer(computer *logmein.Computer) {
	svr.RLock()
	defer svr.RUnlock()

	// receivedThisComputer map should help prevent duplicate computers from crossing the wire
	receivedThisComputer := make(map[chan<- *logmein.Computer]bool)

	if subs, ok := svr.hostIDSubscribers[computer.HostID()]; ok {
		for _, sub := range subs {
			if _, ok := receivedThisComputer[sub]; !ok {
				sub <- computer
				receivedThisComputer[sub] = true
			}
		}
	} else if subs, ok := svr.hostIDSubscribers[computer.OldHostID()]; ok {
		// presently I know of no situation where we ever see an "OldHostID != HostID" except at creation where OldHostID == 0
		for _, sub := range subs {
			if _, ok := receivedThisComputer[sub]; !ok {
				sub <- computer
				receivedThisComputer[sub] = true
			}
		}
	}

	for _, re := range svr.regexpSet {
		if subs, ok := svr.nameMatchSubscribers[re]; ok {
			if re.MatchString(computer.Name()) || re.MatchString(computer.OldName()) {
				for _, sub := range subs {
					if _, ok := receivedThisComputer[sub]; !ok {
						sub <- computer
						receivedThisComputer[sub] = true
					}
				}
			}
		}
	}

	for ipNetStr, subs := range svr.ipMatchSubscribers {
		_, ipNet, err := net.ParseCIDR(ipNetStr)
		if err == nil {
			if ipNet.Contains(computer.IPAddress()) || ipNet.Contains(computer.OldIPAddress()) {
				for _, sub := range subs {
					sub <- computer
				}
			}
		}
	}
}
Exemple #2
0
func convertComputerToGRPC(c *logmein.Computer) *lmifeedr.Computer {
	v := &lmifeedr.Computer{
		HostID:    c.HostID(),
		OldHostID: c.OldHostID(),
		Name:      c.Name(),
		OldName:   c.OldName(),
		Status:    int32(c.Status()),
		OldStatus: int32(c.OldStatus()),
		ChangeSet: uint32(c.GetChangeSet()),
	}
	if c.IPAddress() != nil {
		v.Ip = c.IPAddress().String()
	}
	if c.OldIPAddress() != nil {
		v.OldIp = c.OldIPAddress().String()
	}
	return v
}