5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 14:10:28 +00:00

fix merge conflict

This commit is contained in:
Arceliar 2019-01-26 14:27:37 -06:00
commit 6ef0e47632
2 changed files with 29 additions and 11 deletions

View File

@ -117,6 +117,8 @@ func bubbleUpTo(sets []keySet, num int) []keySet {
var tmp = sets[i] var tmp = sets[i]
sets[i] = sets[i+1] sets[i] = sets[i+1]
sets[i+1] = tmp sets[i+1] = tmp
} else {
break
} }
} }
return sets return sets

View File

@ -554,17 +554,30 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
} }
// code isn't multithreaded so appending to this is safe // code isn't multithreaded so appending to this is safe
coords := sinfo.coords coords := sinfo.coords
// Read IPv6 flowlabel field (20 bits). // Work out the flowkey - this is used to determine which switch queue
// Assumes packet at least contains IPv6 header. // traffic will be pushed to in the event of congestion
flowkey := uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3]) var flowkey uint64
// Check if the flowlabel was specified // Get the IP protocol version from the packet
if flowkey == 0 { switch bs[0] & 0xf0 {
// Does the packet meet the minimum UDP packet size? (others are bigger) case 0x40: // IPv4 packet
if len(bs) >= 48 { // Check the packet meets minimum UDP packet length
// Is the protocol TCP, UDP, SCTP? if len(bs) >= 24 {
// Is the protocol TCP, UDP or SCTP?
if bs[9] == 0x06 || bs[9] == 0x11 || bs[9] == 0x84 {
ihl := bs[0] & 0x0f * 4 // Header length
flowkey = uint64(bs[9])<<32 /* proto */ |
uint64(bs[ihl+0])<<24 | uint64(bs[ihl+1])<<16 /* sport */ |
uint64(bs[ihl+2])<<8 | uint64(bs[ihl+3]) /* dport */
}
}
case 0x60: // IPv6 packet
// Check if the flowlabel was specified in the packet header
flowkey = uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
// If the flowlabel isn't present, make protokey from proto | sport | dport
// if the packet meets minimum UDP packet length
if flowkey == 0 && len(bs) >= 48 {
// Is the protocol TCP, UDP or SCTP?
if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 { if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 {
// if flowlabel was unspecified (0), try to use known protocols' ports
// protokey: proto | sport | dport
flowkey = uint64(bs[6])<<32 /* proto */ | flowkey = uint64(bs[6])<<32 /* proto */ |
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ | uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ |
uint64(bs[42])<<8 | uint64(bs[43]) /* dport */ uint64(bs[42])<<8 | uint64(bs[43]) /* dport */
@ -612,5 +625,8 @@ func (sinfo *sessionInfo) doRecv(p *wire_trafficPacket) {
sinfo.updateNonce(&p.Nonce) sinfo.updateNonce(&p.Nonce)
sinfo.time = time.Now() sinfo.time = time.Now()
sinfo.bytesRecvd += uint64(len(bs)) sinfo.bytesRecvd += uint64(len(bs))
sinfo.core.router.toRecv <- router_recvPacket{bs, sinfo} select {
case sinfo.core.router.toRecv <- router_recvPacket{bs, sinfo}:
default: // avoid deadlocks, maybe do this somewhere else?...
}
} }