Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding OnOpenComplete #122

Merged
merged 1 commit into from
Oct 27, 2021
Merged

Adding OnOpenComplete #122

merged 1 commit into from
Oct 27, 2021

Conversation

daonb
Copy link
Contributor

@daonb daonb commented Oct 25, 2021

Description

Following #81 and the discussion there, I copied the code from #56 and simplified it - the change now adds a special event handler to be used by the channel opener.

With the change, and a small pion/webrtc PR which will soon follow, the peer that opens a channel can use OnOpenComplete to set a handler. Unlike the OnOpen handler, this handler can send data over the channel.

Reference issue

Fixes #81

@codecov
Copy link

codecov bot commented Oct 25, 2021

Codecov Report

Merging #122 (e992e95) into master (4e5f40b) will increase coverage by 1.98%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
+ Coverage   65.97%   67.96%   +1.98%     
==========================================
  Files           4        4              
  Lines         194      206      +12     
==========================================
+ Hits          128      140      +12     
  Misses         41       41              
  Partials       25       25              
Flag Coverage Δ
go 67.96% <100.00%> (+1.98%) ⬆️
wasm 67.96% <100.00%> (+1.98%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
datachannel.go 70.94% <100.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e5f40b...e992e95. Read the comment docs.

Copy link

@ashellunts ashellunts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

datachannel_test.go Outdated Show resolved Hide resolved
datachannel_test.go Outdated Show resolved Hide resolved
datachannel_test.go Outdated Show resolved Hide resolved
@@ -44,6 +45,10 @@ type DataChannel struct {
bytesSent uint64
bytesReceived uint64

mu sync.Mutex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if we can reduce count of used mutexes as this is often source of bugs. Not sure though if it is possible in this case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daonb why do need mutexes? As I see both code paths are invoked by library client.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sean-Der what is your opinion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a mutext to protect from callback changes just as the library is calling the callback. onOpenComplete is called when the channel ack is received from the remote peer.

This pattern is copied from webrtc's OnDataChannel and it makes sense here as we shouldn't make any assumption as to when the client changes the callback.

Copy link

@ashellunts ashellunts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@ashellunts ashellunts self-requested a review October 25, 2021 13:26
Copy link

@ashellunts ashellunts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore this comment

@ashellunts
Copy link

ashellunts commented Oct 27, 2021 via email

@Sean-Der
Copy link
Member

LGTM!

@ashellunts Pion has always provided a thread safe API. I don't think we will hit a lot of lock contention on this mutex, so this should be pretty safe!

@daonb would you mind just squashing down into one commit?

Thank you so much for the fix and thank you for the good reviews @ashellunts :)

@ashellunts
Copy link

LGTM!

@ashellunts Pion has always provided a thread safe API. I don't think we will hit a lot of lock contention on this mutex, so this should be pretty safe!

@daonb would you mind just squashing down into one commit?

Thank you so much for the fix and thank you for the good reviews @ashellunts :)

Thank you for your feedback, Sean!

@daonb
Copy link
Contributor Author

daonb commented Oct 27, 2021

Thanks guys for the quick review.

Be happy to squash & merge only WASM is failing. Is it the PR's fault? or is there some deep magic that will let me merge?

@Sean-Der Sean-Der force-pushed the handleack branch 2 times, most recently from 8ea0d98 to 629ac6a Compare October 27, 2021 17:58
@ashellunts
Copy link

@Sean-Der how did you push to repository of @daonb?

@Sean-Der
Copy link
Member

@ashellunts yea! I am debugging the WASM issue

Add a OnOpenComplete handler. This allows us to fire OnOpen messages
correctly in pion/webrtc

Fixes pion#81
Relates to pion/webrtc#1063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly handle ChannelAck message
3 participants