Skip to content

Commit

Permalink
Revert "relay fixes for multi-IP hosts"
Browse files Browse the repository at this point in the history
This reverts commit ee4495c.
  • Loading branch information
JackDoanRivian committed Oct 15, 2024
1 parent 6e55c1d commit 9036c07
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions relay_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ func (rm *relayManager) handleCreateRelayRequest(v cert.Version, h *HostInfo, f

msg, err := resp.Marshal()
if err != nil {
logMsg.WithError(err).Error("relayManager Failed to marshal Control CreateRelayResponse message to create relay")
logMsg.
WithError(err).Error("relayManager Failed to marshal Control CreateRelayResponse message to create relay")
} else {
f.SendMessageToHostInfo(header.Control, 0, h, msg, make([]byte, 12), make([]byte, mtu))
rm.l.WithFields(logrus.Fields{
Expand Down Expand Up @@ -334,27 +335,29 @@ func (rm *relayManager) handleCreateRelayRequest(v cert.Version, h *HostInfo, f
}

if v == cert.Version1 {
if !from.Is4() {
if !h.vpnAddrs[0].Is4() {
//TODO: log it
return
}
b := from.As4()

b := h.vpnAddrs[0].As4()
req.OldRelayFromAddr = binary.BigEndian.Uint32(b[:])
b = target.As4()
req.OldRelayToAddr = binary.BigEndian.Uint32(b[:])
} else {
req.RelayFromAddr = netAddrToProtoAddr(from)
req.RelayFromAddr = netAddrToProtoAddr(h.vpnAddrs[0])
req.RelayToAddr = netAddrToProtoAddr(target)
}

msg, err := req.Marshal()
if err != nil {
logMsg.WithError(err).Error("relayManager Failed to marshal Control message to create relay")
logMsg.
WithError(err).Error("relayManager Failed to marshal Control message to create relay")
} else {
f.SendMessageToHostInfo(header.Control, 0, peer, msg, make([]byte, 12), make([]byte, mtu))
rm.l.WithFields(logrus.Fields{
//TODO: IPV6-WORK another lazy used to use the req object
"relayFrom": from,
"relayFrom": h.vpnAddrs[0],
"relayTo": target,
"initiatorRelayIndex": req.InitiatorRelayIndex,
"responderRelayIndex": req.ResponderRelayIndex,
Expand All @@ -372,7 +375,8 @@ func (rm *relayManager) handleCreateRelayRequest(v cert.Version, h *HostInfo, f
}
_, err := AddRelay(rm.l, h, f.hostMap, target, &m.InitiatorRelayIndex, ForwardingType, state)
if err != nil {
logMsg.WithError(err).Error("relayManager Failed to allocate a local index for relay")
logMsg.
WithError(err).Error("relayManager Failed to allocate a local index for relay")
return
}
} else {
Expand All @@ -393,28 +397,29 @@ func (rm *relayManager) handleCreateRelayRequest(v cert.Version, h *HostInfo, f
}

if v == cert.Version1 {
if !from.Is4() {
if !h.vpnAddrs[0].Is4() {
//TODO: log it
return
}

b := from.As4()
b := h.vpnAddrs[0].As4()
resp.OldRelayFromAddr = binary.BigEndian.Uint32(b[:])
b = target.As4()
resp.OldRelayToAddr = binary.BigEndian.Uint32(b[:])
} else {
resp.RelayFromAddr = netAddrToProtoAddr(from)
resp.RelayFromAddr = netAddrToProtoAddr(h.vpnAddrs[0])
resp.RelayToAddr = netAddrToProtoAddr(target)
}

msg, err := resp.Marshal()
if err != nil {
rm.l.WithError(err).Error("relayManager Failed to marshal Control CreateRelayResponse message to create relay")
rm.l.
WithError(err).Error("relayManager Failed to marshal Control CreateRelayResponse message to create relay")
} else {
f.SendMessageToHostInfo(header.Control, 0, h, msg, make([]byte, 12), make([]byte, mtu))
rm.l.WithFields(logrus.Fields{
//TODO: IPV6-WORK more lazy, used to use resp object
"relayFrom": from,
"relayFrom": h.vpnAddrs[0],
"relayTo": target,
"initiatorRelayIndex": resp.InitiatorRelayIndex,
"responderRelayIndex": resp.ResponderRelayIndex,
Expand Down

0 comments on commit 9036c07

Please sign in to comment.