Skip to content

Commit

Permalink
🐛 failed to new transport in arm arch
Browse files Browse the repository at this point in the history
  • Loading branch information
PeerXu committed Feb 24, 2021
1 parent a981067 commit f9b0f65
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/meepo/new_teleportation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (mp *Meepo) NewTeleportation(id string, remote net.Addr, opts ...NewTelepor
logger.WithError(err).Errorf("failed to new teleportation source")
return nil, err
}
tp.OnTransportState(transport.TransportStateFailed, func(hid int64) {
tp.OnTransportState(transport.TransportStateFailed, func(hid transport.HandleID) {
ts.Close()
tp.UnsetOnTransportState(transport.TransportStateFailed, hid)
})
Expand Down Expand Up @@ -232,7 +232,7 @@ func (mp *Meepo) onNewTeleportation(dc transport.DataChannel, in interface{}) {
mp.sendMessage(dc, mp.invertMessageWithError(req, err))
return
}
tp.OnTransportState(transport.TransportStateFailed, func(hid int64) {
tp.OnTransportState(transport.TransportStateFailed, func(hid transport.HandleID) {
ts.Close()
ts.Transport().UnsetOnTransportState(transport.TransportStateFailed, hid)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/meepo/new_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (mp *Meepo) NewTransport(peerID string) (transport.Transport, error) {
tp.OnDataChannelCreate("sys", mp.onTransportSysDataChannelCreate)
logger.Tracef("register on data channel create handler")

tp.OnTransportState(transport.TransportStateFailed, func(int64) {
tp.OnTransportState(transport.TransportStateFailed, func(transport.HandleID) {
mp.removeTransport(peerID)
logger.Tracef("remove transport")
mp.removeTeleportationsByPeerID(peerID)
Expand Down Expand Up @@ -132,7 +132,7 @@ func (mp *Meepo) onNewTransport(src *signaling.Descriptor) (*signaling.Descripto
tp.OnDataChannelCreate("sys", mp.onTransportSysDataChannelCreate)
logger.Tracef("register on data channel create handler")

tp.OnTransportState(transport.TransportStateFailed, func(int64) {
tp.OnTransportState(transport.TransportStateFailed, func(transport.HandleID) {
mp.removeTransport(peerID)
logger.Tracef("remove transport")
mp.removeTeleportationsByPeerID(peerID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/meepo/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (mp *Meepo) Teleport(peerID string, remote net.Addr, opts ...TeleportOption
return nil, err
}
wg.Add(1)
tp.OnTransportState(transport.TransportStateConnected, func(hid int64) {
tp.OnTransportState(transport.TransportStateConnected, func(hid transport.HandleID) {
wg.Done()
tp.UnsetOnTransportState(transport.TransportStateConnected, hid)
})
Expand Down
7 changes: 4 additions & 3 deletions pkg/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ func (t TransportState) String() string {
return transportStateStr[t]
}

type OnTransportStateHandler func(int64)
type HandleID = uint32
type OnTransportStateHandler func(HandleID)

type Transport interface {
PeerID() string
Err() error
Close() error
OnTransportStateChange(func(TransportState))
OnTransportState(TransportState, func(hid int64)) int64
UnsetOnTransportState(s TransportState, hid int64)
OnTransportState(TransportState, func(hid HandleID)) HandleID
UnsetOnTransportState(s TransportState, hid HandleID)
TransportState() TransportState

DataChannels() ([]DataChannel, error)
Expand Down
16 changes: 8 additions & 8 deletions pkg/transport/webrtc/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type WebrtcTransport struct {
opt objx.Map
logger logrus.FieldLogger
peerID string
handleIdx int64
handleIdx transport.HandleID

pc *webrtc.PeerConnection

Expand All @@ -40,7 +40,7 @@ type WebrtcTransport struct {
onTransportStateChangeHandler func(transport.TransportState)
onDataChannelCreateHandlers map[string]transport.OnDataChannelCreateHandler

onTransportStateHandlers map[transport.TransportState]map[int64]transport.OnTransportStateHandler
onTransportStateHandlers map[transport.TransportState]map[transport.HandleID]transport.OnTransportStateHandler

channelsMtx sync.Mutex
onTransportStateChangeHandlerMtx sync.Mutex
Expand Down Expand Up @@ -94,13 +94,13 @@ func (wt *WebrtcTransport) OnTransportStateChange(f func(transport.TransportStat
wt.onTransportStateChangeHandlerMtx.Unlock()
}

func (wt *WebrtcTransport) OnTransportState(s transport.TransportState, f func(int64)) int64 {
hid := atomic.AddInt64(&wt.handleIdx, 1)
func (wt *WebrtcTransport) OnTransportState(s transport.TransportState, f func(transport.HandleID)) transport.HandleID {
hid := atomic.AddUint32(&wt.handleIdx, 1)

wt.onTransportStateHandlersMtx.Lock()
hm, ok := wt.onTransportStateHandlers[s]
if !ok {
hm = make(map[int64]transport.OnTransportStateHandler)
hm = make(map[transport.HandleID]transport.OnTransportStateHandler)
wt.onTransportStateHandlers[s] = hm
}
hm[hid] = f
Expand All @@ -113,7 +113,7 @@ func (wt *WebrtcTransport) OnTransportState(s transport.TransportState, f func(i
return hid
}

func (wt *WebrtcTransport) UnsetOnTransportState(s transport.TransportState, hid int64) {
func (wt *WebrtcTransport) UnsetOnTransportState(s transport.TransportState, hid transport.HandleID) {
wt.onTransportStateHandlersMtx.Lock()
if hm, ok := wt.onTransportStateHandlers[s]; ok {
delete(hm, hid)
Expand All @@ -132,7 +132,7 @@ func (wt *WebrtcTransport) onTransportState(s transport.TransportState) {
hm, ok := wt.onTransportStateHandlers[s]
if ok {
for hid, f := range hm {
go func(hid int64, f func(int64)) {
go func(hid transport.HandleID, f func(transport.HandleID)) {
f(hid)
logger.WithField("handleID", hid).Tracef("handle on transport state")
}(hid, f)
Expand Down Expand Up @@ -510,7 +510,7 @@ func NewWebrtcTransport(opts ...transport.NewTransportOption) (transport.Transpo
channels: make(map[string]transport.DataChannel),

onDataChannelCreateHandlers: make(map[string]transport.OnDataChannelCreateHandler),
onTransportStateHandlers: make(map[transport.TransportState]map[int64]transport.OnTransportStateHandler),
onTransportStateHandlers: make(map[transport.TransportState]map[transport.HandleID]transport.OnTransportStateHandler),
}

switch role {
Expand Down

0 comments on commit f9b0f65

Please sign in to comment.