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

TCP forwarding #139

Merged
merged 36 commits into from
Feb 11, 2014
Merged

TCP forwarding #139

merged 36 commits into from
Feb 11, 2014

Conversation

timkurvers
Copy link
Contributor

Initial implementation for broadcasting and receiving file system modifications over TCP, as discussed in #57.

@timkurvers
Copy link
Contributor Author

The Celluloid::IO::TCPSocket connectivity issues turned out to be Celluloid internally using a DNS-resolver, which would not function correctly if the broadcaster had been set to listen to localhost. Unless explicitly specified the broadcaster now listens on all addresses by default.

TCP::Listener.new(target, :broadcaster, *args, &block)
else
Listener.new(*args, &block)
end
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of using another method for forwarding, maybe something like Listen.for(target, 'dir_path') or Listen.to_forward...

I don't really like this big if in the to method, or maybe move it to another _listener_class private method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From an aesthetic perspective I like how Listen.to 'foo', forward_to: '10.0.0.1' flows, as well as Listen.on '10.0.0.1:4000', but I agree on the current implementation being rather hacky and far from ideal.

What would the _listener_class private method you had in mind look like?

Copy link
Member

Choose a reason for hiding this comment

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

Mmm after some more thinking and because how TCP::Listener is different to initialize than Listener, _listener_class idea seems not so good anymore. :(

I agree than Listen.to('foo', forward_to: '10.0.0.1') is quite straightforward. So don't touch it for now. Thanks!

@thibaudgg
Copy link
Member

Please rebase from master, I have fixed the specs on Travis. :)

@thibaudgg
Copy link
Member

Overall I really like the coding style, thanks for this awesome PR. CodeClimate will like it!

I'll give it a try in the next days.

@thibaudgg
Copy link
Member

I have test it locally with:

broadcaster.rb:

require 'listen'
listener = Listen.to(Dir.pwd, forward_to: '127.0.0.1:4000')
listener.start
sleep

receiver.rb

require 'listen'
listener = Listen.on('127.0.0.1:4000') do |modified, added, removed|
  puts "-----------"
  puts "modified: #{modified}"
  puts "added:    #{added}"
  puts "removed:  #{removed}"
end
listener.start
sleep

A problem is that first modification is always detected as an addition because receiver.rb isn't able to build a record on start. The solution is to give the responsibility of change type (modified, added or removed) detection on the broadcaster side and sent change with it. Makes sense?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling a0afe4f on timkurvers:feature/tcp-forwarding into * on guard:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e3a8a97 on timkurvers:feature/tcp-forwarding into * on guard:master*.

@timkurvers
Copy link
Contributor Author

@thibaudgg I seem to get the first modification detected as addition even on master or on the TCP broadcaster, not just the TCP recipient. Can you confirm that?

Regardless, your assessment of the TCP receiver not handling this correctly is accurate, so I'll look into that.

Any idea what is up with the Changes Unknown when pulling.. from Coveralls/Travis?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f5d4328 on timkurvers:feature/tcp-forwarding into * on guard:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 00d0c77 on timkurvers:feature/tcp-forwarding into * on guard:master*.

@thibaudgg
Copy link
Member

@timkurvers for me, on OS X with darwin and polling adapter, first detection is detected as modification. On which platform are you?

It seems you manage to fix Changes Unknown when pulling.. right? Thanks!

require 'listen'
listener = Listen.to(Dir.pwd) do |modified, added, removed|
  puts "-----------"
  puts "modified: #{modified}"
  puts "added:    #{added}"
  puts "removed:  #{removed}"
end
listener.start
sleep

@timkurvers
Copy link
Contributor Author

On OSX here as well. When listening to directories that are not the current working directory I seem to get the issue:

require 'listen'
listener = Listen.to 'lib' do |*args|
  p args
end
listener.start
sleep
$ touch lib/listen.rb
[[], ["/listen/lib/listen/adapter/windows.rb", "/listen/lib/listen/adapter/polling.rb",
...
"/listen/lib/listen/adapter.rb", "/listen/lib/listen.rb"], []]

With the polling adapter however, that does not occur:

require 'listen'
listener = Listen.to 'lib', force_polling: true do |*args|
  p args
end
listener.start
sleep
$ touch lib/listen.rb
[["lib/listen.rb"], [], []]

The Changes Unknown when pulling-message is still showing up for me here, not sure what's up. I did manage to fix the build, that turned out to be an encoding oversight.

@thibaudgg
Copy link
Member

Mmm, I'm not able to reproduce it even using an external directory, what kind of hard drive do you have (SSD here)? Please try to wait some time before touching the file to see if it change anything.

Where are you seeing The Changes Unknown when pulling... message? In travis? Could you give an url please?

@timkurvers
Copy link
Contributor Author

On an SSD here, too. I tried waiting a bit but that didn't change anything. I'm running the examples from within bundle exec pry, is that an issue?

The Changes Unknown when pulling-message are here in this thread by Coveralls, a couple of posts above.

@thibaudgg
Copy link
Member

I launch it from a ruby file with bundle exec ruby ./example.rb, could you try it as well? Thanks.

Ok I see the errors message, I think we can skip it for now...

@timkurvers
Copy link
Contributor Author

Have tried it with the following bundle exec ruby example.rb, containing:

#!/usr/bin/env ruby
require 'listen'

listener = Listen.to 'lib', 'spec', debug: true do |*args|
  p args
end

listener.start
sleep

The first file added, modified or removed in each of those directories seem to fire of additions. Anything that would help debugging this? Gemfile.lock?

@thibaudgg
Copy link
Member

Ok nice, I was able to reproduce it. It's only happen when directory aren't given with absolute path. I'll fix it, thanks!

@thibaudgg
Copy link
Member

Fixed in 146b5cd, could you rebase and give it a try please? Thanks!

@coveralls
Copy link

Coverage Status

Coverage increased (+7.15%) when pulling 45ad9d8 on timkurvers:feature/tcp-forwarding into 5f0c9b7 on guard:master.

@timkurvers
Copy link
Contributor Author

Excellent, works fine! I can also confirm the TCP receiver correctly relies on the broadcasted changes.

@thibaudgg
Copy link
Member

Great news, I just released Listen 2.0.0, so this feature will be added in 2.1.0.
You just need to add some more specs and it will be merge-able right?

@timkurvers
Copy link
Contributor Author

Yep! I will most probably need some help with speccing threaded/Celluloid'd code though.

@thibaudgg
Copy link
Member

Sure, feel free to ask for help.

@ghost
Copy link

ghost commented Oct 28, 2013

Nice work. Cant wait to see it merged!

@ghost
Copy link

ghost commented Nov 15, 2013

If someone wants to actually try this here's a simple way to build it into guard: https://github.com/johannesbecker/guard/commit/a9c14b514ffd4c64b97ffd8188e5f197f095ada1

Additionally you need to rebase this PR on Listen 2.2 - did so at https://github.com/johannesbecker/listen

Works like a charm 👍

@timkurvers
Copy link
Contributor Author

Thanks for giving this a go @JohannesBecker, much appreciated! I have gotten a bit side-tracked with other projects but hope to be able to spec the PR soonish.

@thibaudgg
Copy link
Member

Great can't wait to merge it!

@thibaudgg
Copy link
Member

@JohannesBecker once merged, it would be great if you could submit your branch to Guard via a PR, thanks!

@timkurvers
Copy link
Contributor Author

The message implementation now uses JSON.

Wasn't really sure where to document TCP forwarding in the README but I felt it was much less of a core feature than the adapters, so it's beneath those. If anything needs to be amended please let me know :)

thibaudgg added a commit that referenced this pull request Feb 11, 2014
@thibaudgg thibaudgg merged commit 9be4f2d into guard:master Feb 11, 2014
@thibaudgg
Copy link
Member

Awesome, @timkurvers thanks a lot for your great work! 2.5.0 released!

@acoulton
Copy link

@timkurvers @thibaudgg thank you for this, it's going to be a major improvement to our workflow.

@timkurvers
Copy link
Contributor Author

Wooo, thanks for merging!

@ideasasylum
Copy link
Contributor

Thank you. Thank you! I had taken a stab at this almost a year ago and it defeated me in the time I had. Kudos!

So, can we use this with guard yet? Well, I've taken a stab at that and got it working really well:

https://github.com/ideasasylum/guard#-o--listen_on-option

I think I need a better host 'listener' script though as it can't be killed from the console

@thibaudgg
Copy link
Member

@ideasasylum great, please submit a PR on Guard. I would be greatly happy to merge it!

@ideasasylum
Copy link
Contributor

@thibaudgg done: guard/guard#555

@thibaudgg
Copy link
Member

@ideasasylum thanks we'll continue the discussion there. (Tomorrow I think)

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.

7 participants