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

Push Publishing #82

Merged
merged 15 commits into from
Nov 17, 2016
Merged

Push Publishing #82

merged 15 commits into from
Nov 17, 2016

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Nov 10, 2016

Implement the /mediachain/node/push protocol for accepting pushes from authorized peers.
Semantics are those of an inverted merge: the source pushes statements, and the receiver merges them and requests objects by reusing the merge protocol implementation.

Closes #23

Implementation:

  • protobufs
  • receiver implementation
  • sender implementation
  • peer authorization/API for authorizing peers
  • namespace filtering in incoming stream

Also: changes mc/nat public ip detection service to ifconfig.co, as ifconfig.me appears to be busted.

Examples

  • Pushing to a remote peer which has authorized us
$ mcclient query "SELECT COUNT(*) FROM images.dpla"
1000
$ mcclient query -r QmSbgwkKxtrBFDoGGwoKqH7soYiL64xpMK5oEYdiRnQGJp "SELECT COUNT(*) FROM images.dpla"
0
$ curl -H "Content-Type: application/text" -d 'SELECT * FROM images.dpla' http://127.0.0.1:9002/push/QmSbgwkKxtrBFDoGGwoKqH7soYiL64xpMK5oEYdiRnQGJp
1000
1001
$ mcclient query -r QmSbgwkKxtrBFDoGGwoKqH7soYiL64xpMK5oEYdiRnQGJp "SELECT COUNT(*) FROM images.dpla"
1000
  • Using the /auth api:
$ mcclient id
Peer ID: QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa
Publisher ID: 4XTTMADSKQUN3jkeZngbtuE35w9y5YnDTicVTeeji7N2Npkey
Info: vyzo testing

$ curl http://127.0.0.1:9002/auth
{}

# Authorize a peer (just self here)
$ curl -H "Content-Type: application/text" -d '*' http://127.0.0.1:9002/auth/QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa
OK
$ curl http://127.0.0.1:9002/auth
{"QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa":["*"]}
$ curl -H "Content-Type: application/text" -d '*,foo.*,bar.baz' http://127.0.0.1:9002/auth/QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa
OK
$ curl http://127.0.0.1:9002/auth
{"QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa":["*","foo.*","bar.baz"]}
$ curl http://127.0.0.1:9002/auth/QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa
*,foo.*,bar.baz

# revoke authorization
$ curl -H "Content-Type: application/text" -d '' http://127.0.0.1:9002/auth/QmeBkfxcaBfA9pvzivRwhF2PM7sXpp4HHQbp7jfTkRCWEa
OK
$ curl http://127.0.0.1:9002/auth
{}

@@ -323,3 +325,8 @@ func (node *Node) doShutdown() {
node.ds.Close()
os.Exit(0)
}

func (node *Node) authorizePush(pid p2p_peer.ID, ns []string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's just make a little table of permitted peers:namespaces for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, more like a table to a list of namespaces (with wildcard support)

@parkan
Copy link
Contributor

parkan commented Nov 10, 2016

Looking good so far

@vyzo vyzo changed the title Push Publishing [WIP] Push Publishing Nov 16, 2016
@@ -119,7 +119,7 @@ func NATConfigFromString(str string) (cfg NATConfig, err error) {
}

func GetPublicIP() (string, error) {
res, err := http.Get("http://ifconfig.me/ip")
res, err := http.Get("http://ifconfig.co/ip")
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to fallback through a couple/one that we run

Copy link
Contributor Author

@vyzo vyzo Nov 17, 2016

Choose a reason for hiding this comment

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

Sure, that's probably a good idea.
The code running ifconfig.co is available at github: https://github.com/martinp/ipd
So we can run it at ifconfig.medichain.io and have fallback to ifconfig.co.

I'll open an enhancement issue and add support once we have the ifconfing server up.


func (auth *PeerAuth) fromJSON(rmap map[string]interface{}) error {
auth.mx.Lock()
defer auth.mx.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

this just executes when it goes out of scope? weird. I guess it's like a finally a bit?

Copy link
Contributor Author

@vyzo vyzo Nov 17, 2016

Choose a reason for hiding this comment

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

It's more like unwind-protect at function-scope.
Each function has an unwind stack, where defer pushes thunks. And at the function epilogue, the unwind stack is poped and the thunks are executed.

return true

case strings.HasSuffix(rule, ".*"):
if strings.HasPrefix(ns, rule[:len(rule)-2]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about foo.bar.*.*?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhm, I don't think it's worth the trouble.
I kept it simple and used the same wildcard semantics we have in MCQL.
If it proves to be insufficient for some use case, we can generalize to support regexps.

@vyzo vyzo merged commit 6c9d9b6 into master Nov 17, 2016
@vyzo vyzo deleted the vyzo-push-pub branch November 17, 2016 08:11
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.

2 participants