| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package network |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
|
| 20 |
"inet.af/netstack/tcpip" |
| 21 |
"inet.af/netstack/tcpip/stack" |
| 22 |
"inet.af/netstack/tcpip/transport" |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
func (e *Endpoint) Resume(s *stack.Stack) { |
| 27 |
e.mu.Lock() |
| 28 |
defer e.mu.Unlock() |
| 29 |
|
| 30 |
e.stack = s |
| 31 |
|
| 32 |
for m := range e.multicastMemberships { |
| 33 |
if err := e.stack.JoinGroup(e.netProto, m.nicID, m.multicastAddr); err != nil { |
| 34 |
panic(fmt.Sprintf("e.stack.JoinGroup(%d, %d, %s): %s", e.netProto, m.nicID, m.multicastAddr, err)) |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
info := e.Info() |
| 39 |
|
| 40 |
switch state := e.State(); state { |
| 41 |
case transport.DatagramEndpointStateInitial, transport.DatagramEndpointStateClosed: |
| 42 |
case transport.DatagramEndpointStateBound: |
| 43 |
if len(info.ID.LocalAddress) != 0 && !e.isBroadcastOrMulticast(info.RegisterNICID, e.effectiveNetProto, info.ID.LocalAddress) { |
| 44 |
if e.stack.CheckLocalAddress(info.RegisterNICID, e.effectiveNetProto, info.ID.LocalAddress) == 0 { |
| 45 |
panic(fmt.Sprintf("got e.stack.CheckLocalAddress(%d, %d, %s) = 0, want != 0", info.RegisterNICID, e.effectiveNetProto, info.ID.LocalAddress)) |
| 46 |
} |
| 47 |
} |
| 48 |
case transport.DatagramEndpointStateConnected: |
| 49 |
var err tcpip.Error |
| 50 |
multicastLoop := e.ops.GetMulticastLoop() |
| 51 |
e.connectedRoute, err = e.stack.FindRoute(info.RegisterNICID, info.ID.LocalAddress, info.ID.RemoteAddress, e.effectiveNetProto, multicastLoop) |
| 52 |
if err != nil { |
| 53 |
panic(fmt.Sprintf("e.stack.FindRoute(%d, %s, %s, %d, %t): %s", info.RegisterNICID, info.ID.LocalAddress, info.ID.RemoteAddress, e.effectiveNetProto, multicastLoop, err)) |
| 54 |
} |
| 55 |
default: |
| 56 |
panic(fmt.Sprintf("unhandled state = %s", state)) |
| 57 |
} |
| 58 |
} |