mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-31 16:11:03 +01:00 
			
		
		
		
	Expanded response marshal methods to support legacy and Noise
This commit is contained in:
		
							parent
							
								
									f9a2a2b57a
								
							
						
					
					
						commit
						a87a9636e3
					
				| @ -21,7 +21,7 @@ func (h *Headscale) getMapResponseData( | ||||
| 	} | ||||
| 
 | ||||
| 	if isNoise { | ||||
| 		return h.marshalResponse(mapResponse, mapRequest.Compress, key.MachinePublic{}) | ||||
| 		return h.marshalMapResponse(mapResponse, key.MachinePublic{}, mapRequest.Compress) | ||||
| 	} | ||||
| 
 | ||||
| 	var machineKey key.MachinePublic | ||||
| @ -35,7 +35,7 @@ func (h *Headscale) getMapResponseData( | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return h.marshalResponse(mapResponse, mapRequest.Compress, machineKey) | ||||
| 	return h.marshalMapResponse(mapResponse, machineKey, mapRequest.Compress) | ||||
| } | ||||
| 
 | ||||
| func (h *Headscale) getMapKeepAliveResponseData( | ||||
| @ -48,7 +48,7 @@ func (h *Headscale) getMapKeepAliveResponseData( | ||||
| 	} | ||||
| 
 | ||||
| 	if isNoise { | ||||
| 		return h.marshalResponse(keepAliveResponse, mapRequest.Compress, key.MachinePublic{}) | ||||
| 		return h.marshalMapResponse(keepAliveResponse, key.MachinePublic{}, mapRequest.Compress) | ||||
| 	} | ||||
| 
 | ||||
| 	var machineKey key.MachinePublic | ||||
| @ -62,13 +62,32 @@ func (h *Headscale) getMapKeepAliveResponseData( | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return h.marshalResponse(keepAliveResponse, mapRequest.Compress, machineKey) | ||||
| 	return h.marshalMapResponse(keepAliveResponse, machineKey, mapRequest.Compress) | ||||
| } | ||||
| 
 | ||||
| func (h *Headscale) marshalResponse( | ||||
| 	resp interface{}, | ||||
| 	compression string, | ||||
| 	machineKey key.MachinePublic, | ||||
| ) ([]byte, error) { | ||||
| 	jsonBody, err := json.Marshal(resp) | ||||
| 	if err != nil { | ||||
| 		log.Error(). | ||||
| 			Caller(). | ||||
| 			Err(err). | ||||
| 			Msg("Cannot marshal response") | ||||
| 	} | ||||
| 
 | ||||
| 	if machineKey.IsZero() { // if Noise | ||||
| 		return jsonBody, nil | ||||
| 	} | ||||
| 
 | ||||
| 	return h.privateKey.SealTo(machineKey, jsonBody), nil | ||||
| } | ||||
| 
 | ||||
| func (h *Headscale) marshalMapResponse( | ||||
| 	resp interface{}, | ||||
| 	machineKey key.MachinePublic, | ||||
| 	compression string, | ||||
| ) ([]byte, error) { | ||||
| 	jsonBody, err := json.Marshal(resp) | ||||
| 	if err != nil { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user