mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-28 10:51:44 +01:00 
			
		
		
		
	chore: apply lint recommendations
This commit is contained in:
		
							parent
							
								
									02ae7a0563
								
							
						
					
					
						commit
						4435a4f19d
					
				
							
								
								
									
										2
									
								
								acls.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								acls.go
									
									
									
									
									
								
							| @ -262,7 +262,7 @@ func expandAlias( | |||||||
| 				} | 				} | ||||||
| 				if len(ips) == 0 { | 				if len(ips) == 0 { | ||||||
| 					return ips, fmt.Errorf( | 					return ips, fmt.Errorf( | ||||||
| 						"%w. %v isn't owned by a TagOwner and no forced tags are defined.", | 						"%w. %v isn't owned by a TagOwner and no forced tags are defined", | ||||||
| 						errInvalidTag, | 						errInvalidTag, | ||||||
| 						alias, | 						alias, | ||||||
| 					) | 					) | ||||||
|  | |||||||
| @ -498,13 +498,13 @@ func nodesToPtables( | |||||||
| 			namespace = pterm.LightYellow(machine.Namespace.Name) | 			namespace = pterm.LightYellow(machine.Namespace.Name) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		var IpV4Address string | 		var IPV4Address string | ||||||
| 		var IpV6Address string | 		var IPV6Address string | ||||||
| 		for _, addr := range machine.IpAddresses { | 		for _, addr := range machine.IpAddresses { | ||||||
| 			if netaddr.MustParseIP(addr).Is4() { | 			if netaddr.MustParseIP(addr).Is4() { | ||||||
| 				IpV4Address = addr | 				IPV4Address = addr | ||||||
| 			} else { | 			} else { | ||||||
| 				IpV6Address = addr | 				IPV6Address = addr | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -513,7 +513,7 @@ func nodesToPtables( | |||||||
| 			machine.Name, | 			machine.Name, | ||||||
| 			nodeKey.ShortString(), | 			nodeKey.ShortString(), | ||||||
| 			namespace, | 			namespace, | ||||||
| 			strings.Join([]string{IpV4Address, IpV6Address}, ", "), | 			strings.Join([]string{IPV4Address, IPV6Address}, ", "), | ||||||
| 			strconv.FormatBool(ephemeral), | 			strconv.FormatBool(ephemeral), | ||||||
| 			lastSeenTime, | 			lastSeenTime, | ||||||
| 			online, | 			online, | ||||||
|  | |||||||
| @ -128,7 +128,7 @@ func (h *Headscale) DERPHandler(ctx *gin.Context) { | |||||||
| 
 | 
 | ||||||
| 	if !fastStart { | 	if !fastStart { | ||||||
| 		pubKey := h.privateKey.Public() | 		pubKey := h.privateKey.Public() | ||||||
| 		pubKeyStr := pubKey.UntypedHexString() | 		pubKeyStr := pubKey.UntypedHexString() // nolint
 | ||||||
| 		fmt.Fprintf(conn, "HTTP/1.1 101 Switching Protocols\r\n"+ | 		fmt.Fprintf(conn, "HTTP/1.1 101 Switching Protocols\r\n"+ | ||||||
| 			"Upgrade: DERP\r\n"+ | 			"Upgrade: DERP\r\n"+ | ||||||
| 			"Connection: Upgrade\r\n"+ | 			"Connection: Upgrade\r\n"+ | ||||||
|  | |||||||
| @ -664,9 +664,11 @@ func getTags( | |||||||
| 	aclPolicy *ACLPolicy, | 	aclPolicy *ACLPolicy, | ||||||
| 	machine Machine, | 	machine Machine, | ||||||
| 	stripEmailDomain bool, | 	stripEmailDomain bool, | ||||||
| ) (validTags []string, invalidTags []string) { | ) ([]string, []string) { | ||||||
|  | 	validTags := make([]string, 0) | ||||||
|  | 	invalidTags := make([]string, 0) | ||||||
| 	if aclPolicy == nil { | 	if aclPolicy == nil { | ||||||
| 		return | 		return validTags, invalidTags | ||||||
| 	} | 	} | ||||||
| 	validTagMap := make(map[string]bool) | 	validTagMap := make(map[string]bool) | ||||||
| 	invalidTagMap := make(map[string]bool) | 	invalidTagMap := make(map[string]bool) | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								poll.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								poll.go
									
									
									
									
									
								
							| @ -20,6 +20,10 @@ const ( | |||||||
| 	updateCheckInterval = 10 * time.Second | 	updateCheckInterval = 10 * time.Second | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | type contextKey string | ||||||
|  | 
 | ||||||
|  | const machineNameContextKey = contextKey("machineName") | ||||||
|  | 
 | ||||||
| // PollNetMapHandler takes care of /machine/:id/map
 | // PollNetMapHandler takes care of /machine/:id/map
 | ||||||
| //
 | //
 | ||||||
| // This is the busiest endpoint, as it keeps the HTTP long poll that updates
 | // This is the busiest endpoint, as it keeps the HTTP long poll that updates
 | ||||||
| @ -272,7 +276,7 @@ func (h *Headscale) PollNetMapStream( | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		ctx := context.WithValue(ctx.Request.Context(), "machineName", machine.Name) | 		ctx := context.WithValue(ctx.Request.Context(), machineNameContextKey, machine.Name) | ||||||
| 
 | 
 | ||||||
| 		ctx, cancel := context.WithCancel(ctx) | 		ctx, cancel := context.WithCancel(ctx) | ||||||
| 		defer cancel() | 		defer cancel() | ||||||
| @ -576,12 +580,12 @@ func (h *Headscale) scheduledPollWorker( | |||||||
| 
 | 
 | ||||||
| 	defer closeChanWithLog( | 	defer closeChanWithLog( | ||||||
| 		updateChan, | 		updateChan, | ||||||
| 		fmt.Sprint(ctx.Value("machineName")), | 		fmt.Sprint(ctx.Value(machineNameContextKey)), | ||||||
| 		"updateChan", | 		"updateChan", | ||||||
| 	) | 	) | ||||||
| 	defer closeChanWithLog( | 	defer closeChanWithLog( | ||||||
| 		keepAliveChan, | 		keepAliveChan, | ||||||
| 		fmt.Sprint(ctx.Value("machineName")), | 		fmt.Sprint(ctx.Value(machineNameContextKey)), | ||||||
| 		"updateChan", | 		"updateChan", | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								utils.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								utils.go
									
									
									
									
									
								
							| @ -136,26 +136,29 @@ func encode( | |||||||
| 	return privKey.SealTo(*pubKey, b), nil | 	return privKey.SealTo(*pubKey, b), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (h *Headscale) getAvailableIPs() (ips MachineAddresses, err error) { | func (h *Headscale) getAvailableIPs() (MachineAddresses, error) { | ||||||
|  | 	var ips MachineAddresses | ||||||
|  | 	var err error | ||||||
| 	ipPrefixes := h.cfg.IPPrefixes | 	ipPrefixes := h.cfg.IPPrefixes | ||||||
| 	for _, ipPrefix := range ipPrefixes { | 	for _, ipPrefix := range ipPrefixes { | ||||||
| 		var ip *netaddr.IP | 		var ip *netaddr.IP | ||||||
| 		ip, err = h.getAvailableIP(ipPrefix) | 		ip, err = h.getAvailableIP(ipPrefix) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return | 			return ips, err | ||||||
| 		} | 		} | ||||||
| 		ips = append(ips, *ip) | 		ips = append(ips, *ip) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return | 	return ips, err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func GetIPPrefixEndpoints(na netaddr.IPPrefix) (network, broadcast netaddr.IP) { | func GetIPPrefixEndpoints(na netaddr.IPPrefix) (netaddr.IP, netaddr.IP) { | ||||||
|  | 	var network, broadcast netaddr.IP | ||||||
| 	ipRange := na.Range() | 	ipRange := na.Range() | ||||||
| 	network = ipRange.From() | 	network = ipRange.From() | ||||||
| 	broadcast = ipRange.To() | 	broadcast = ipRange.To() | ||||||
| 
 | 
 | ||||||
| 	return | 	return network, broadcast | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (h *Headscale) getAvailableIP(ipPrefix netaddr.IPPrefix) (*netaddr.IP, error) { | func (h *Headscale) getAvailableIP(ipPrefix netaddr.IPPrefix) (*netaddr.IP, error) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user