// This function constructs a handshake packet, but does not actually send it
// Sending is done by the handshake manager
This function constructs a handshake packet, but does not actually send it
Sending is done by the handshake manager
// This function constructs a handshake packet but does not actually send it // Sending is done by the handshake manager
func ixHandshakeStage0(f *Interface, vpnIp iputil.VpnIp, hostinfo *HostInfo) {
	if hostinfo.remote == nil {
		f.lightHouse.QueryServer(vpnIp, f)
	}
	err := f.handshakeManager.AddIndexHostInfo(hostinfo)
	if err != nil {
		f.l.WithError(err).WithField("vpnIp", vpnIp).
			WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to generate index")
		return
	}
	ci := hostinfo.ConnectionState
	hsProto := &NebulaHandshakeDetails{
		InitiatorIndex: hostinfo.localIndexId,
		Time:           uint64(time.Now().UnixNano()),
		Cert:           ci.certState.rawCertificateNoKey,
	}
	hsBytes := []byte{}
	hs := &NebulaHandshake{
		Details: hsProto,
	}
	hsBytes, err = proto.Marshal(hs)
	if err != nil {
		f.l.WithError(err).WithField("vpnIp", vpnIp).
			WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to marshal handshake message")
		return
	}
	h := header.Encode(make([]byte, header.Len), header.Version, header.Handshake, header.HandshakeIXPSK0, 0, 1)
	atomic.AddUint64(&ci.atomicMessageCounter, 1)
	msg, _, _, err := ci.H.WriteMessage(h, hsBytes)
	if err != nil {
		f.l.WithError(err).WithField("vpnIp", vpnIp).
			WithField("handshake", m{"stage": 0, "style": "ix_psk0"}).Error("Failed to call noise.WriteMessage")
		return
	}
	ci.window.Update(f.l, 1)
	hostinfo.HandshakePacket[0] = msg
	hostinfo.HandshakeReady = true
	hostinfo.handshakeStart = time.Now()
}
func ixHandshakeStage0 ( f * Interface , vpnIp iputil . VpnIp , hostinfo * HostInfo ) { if hostinfo . remote == nil { f . lightHouse . QueryServer ( vpnIp , f ) } err := f . handshakeManager . AddIndexHostInfo ( hostinfo ) if err != nil { f . l . WithError ( err ) . WithField ( " " , vpnIp ) . WithField ( " " , m { " " : 0 , " " : " " } ) . Error ( " " ) return } ci := hostinfo . ConnectionState hsProto := & NebulaHandshakeDetails { InitiatorIndex : hostinfo . localIndexId , Time : uint64 ( time . Now ( ) . UnixNano ( ) ) , Cert : ci . certState . rawCertificateNoKey , } hsBytes := [ ] byte { } hs := & NebulaHandshake { Details : hsProto , } hsBytes , err = proto . Marshal ( hs ) if err != nil { f . l . WithError ( err ) . WithField ( " " , vpnIp ) . WithField ( " " , m { " " : 0 , " " : " " } ) . Error ( " " ) return } h := header . Encode ( make ( [ ] byte , header . Len ) , header . Version , header . Handshake , header . HandshakeIXPSK0 , 0 , 1 ) atomic . AddUint64 ( & ci . atomicMessageCounter , 1 ) msg , _ , _ , err := ci . H . WriteMessage ( h , hsBytes ) if err != nil { f . l . WithError ( err ) . WithField ( " " , vpnIp ) . WithField ( " " , m { " " : 0 , " " : " " } ) . Error ( " " ) return } ci . window . Update ( f . l , 1 ) hostinfo . HandshakePacket [ 0 ] = msg hostinfo . HandshakeReady = true hostinfo . handshakeStart = time . Now ( ) }
This function constructs a handshake packet, but does not actually send it
Sending is done by the handshake manager
This function constructs a handshake packet but does not actually send it Sending is done by the handshake manager
// This queries the lighthouse if we don't know a remote for the host // We do it here to provoke the lighthouse to preempt our timer wheel and trigger the stage 1 packet to send // more quickly, effect is a quicker handshake. // We are sending handshake packet 1, so we don't expect to receive // handshake packet 1 from the responder