Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

Commit

Permalink
updated from/to language to caller/callee for bridging, closes #661
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Apr 30, 2018
1 parent 3650f93 commit 5067e8b
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 99 deletions.
2 changes: 1 addition & 1 deletion apptest/apptest.go
Expand Up @@ -672,7 +672,7 @@ func StopBridgeApps(bridgeAppServers []*ui.WebServer) {
func buildBridges(h *Holochain, port string, bridgeApps []BridgeApp) (err error) {
// build a bridge to all the bridge apps
for _, app := range bridgeApps {
if app.Side == BridgeFrom {
if app.Side == BridgeCaller {
err = h.BuildBridgeToCaller(&app, port)
} else {
err = h.BuildBridgeToCallee(&app)
Expand Down
14 changes: 7 additions & 7 deletions apptest/apptest_test.go
Expand Up @@ -267,14 +267,14 @@ func TestBuildBridgeToCaller(t *testing.T) {
BridgeZome: "jsSampleZome",
DNA: hCaller.DNAHash(),
Port: callerPort,
BridgeGenesisDataFrom: "callee Data",
BridgeGenesisDataTo: "caller Data",
Side: BridgeFrom,
BridgeGenesisCallerData: "caller Data",
BridgeGenesisCalleeData: "callee Data",
Side: BridgeCaller,
}
ShouldLog(&hCallee.Config.Loggers.App, func() {
err := hCallee.BuildBridgeToCaller(&app, calleePort)
So(err, ShouldBeNil)
}, `testGetBridges:[{"Side":1,"Token":"`, fmt.Sprintf(`bridge genesis to-- other side is:%s bridging data:caller Data`, hCallee.DNAHash().String()))
}, `testGetBridges:[{"Side":1,"Token":"`, fmt.Sprintf(`bridge genesis to-- other side is:%s bridging data:callee Data`, hCallee.DNAHash().String()))

})
}
Expand All @@ -296,9 +296,9 @@ func TestBuildBridgeToCallee(t *testing.T) {
BridgeZome: "jsSampleZome",
DNA: hCallee.DNAHash(),
Port: calleePort,
BridgeGenesisDataFrom: "callee Data",
BridgeGenesisDataTo: "caller Data",
Side: BridgeTo,
BridgeGenesisCallerData: "caller Data",
BridgeGenesisCalleeData: "callee Data",
Side: BridgeCallee,
}
ShouldLog(&hCaller.Config.Loggers.App, func() {
err := hCaller.BuildBridgeToCallee(&app)
Expand Down
38 changes: 19 additions & 19 deletions bridge.go
Expand Up @@ -21,13 +21,13 @@ import (

// BridgeApp describes a data necessary for bridging
type BridgeApp struct {
Name string //Name of other side
DNA Hash // DNA of other side
Side int
BridgeGenesisDataFrom string
BridgeGenesisDataTo string
Port string // only used if side == BridgeTo
BridgeZome string // only used if side == BridgeFrom
Name string //Name of other side
DNA Hash // DNA of other side
Side int
BridgeGenesisCallerData string
BridgeGenesisCalleeData string
Port string // only used if side == BridgeCallee
BridgeZome string // only used if side == BridgeCaller
}

// Bridge holds data returned by GetBridges
Expand Down Expand Up @@ -72,8 +72,8 @@ func (h *Holochain) AddBridgeAsCallee(fromDNA Hash, appData string) (token strin
if err != nil {
return
}
h.Debugf("Running BridgeTo Genesis for %s", zomeName)
err = r.BridgeGenesis(BridgeTo, fromDNA, appData)
h.Debugf("Running BridgeCallee Genesis for %s", zomeName)
err = r.BridgeGenesis(BridgeCallee, fromDNA, appData)
if err != nil {
return
}
Expand Down Expand Up @@ -190,8 +190,8 @@ func (h *Holochain) AddBridgeAsCaller(bridgeZome string, toDNA Hash, token strin
return
}

h.Debugf("Running BridgeFrom Genesis for %s", zome.Name)
err = r.BridgeGenesis(BridgeFrom, toDNA, appData)
h.Debugf("Running BridgeCaller Genesis for %s", zome.Name)
err = r.BridgeGenesis(BridgeCaller, toDNA, appData)
if err != nil {
return
}
Expand Down Expand Up @@ -219,18 +219,18 @@ func (h *Holochain) GetBridgeToken(hash Hash) (token string, url string, err err
return
}

// BuildBridgeToCaller connects h to a running app specified by BridgeApp that will be the Caller, i.e. the the BridgeFrom
// BuildBridgeToCaller connects h to a running app specified by BridgeApp that will be the Caller, i.e. the the BridgeCaller
func (h *Holochain) BuildBridgeToCaller(app *BridgeApp, port string) (err error) {
var token string
token, err = h.AddBridgeAsCallee(app.DNA, app.BridgeGenesisDataTo)
token, err = h.AddBridgeAsCallee(app.DNA, app.BridgeGenesisCalleeData)
if err != nil {
h.Debugf("adding bridge to caller %s from %s failed with %v\n", app.Name, h.Name(), err)
return
}

h.Debugf("%s generated token %s for %s\n", h.Name(), token, app.Name)

data := map[string]string{"Type": "ToCaller", "Zome": app.BridgeZome, "DNA": h.DNAHash().String(), "Token": token, "Port": port, "Data": app.BridgeGenesisDataFrom}
data := map[string]string{"Type": "ToCaller", "Zome": app.BridgeZome, "DNA": h.DNAHash().String(), "Token": token, "Port": port, "Data": app.BridgeGenesisCallerData}
dataJSON, err := json.Marshal(data)
if err != nil {
return
Expand All @@ -252,10 +252,10 @@ func (h *Holochain) BuildBridgeToCaller(app *BridgeApp, port string) (err error)
return
}

// BuildBridgeToCallee connects h to a running app specified by BridgeApp that will be the Callee, i.e. the the BridgeTo
// BuildBridgeToCallee connects h to a running app specified by BridgeApp that will be the Callee, i.e. the the BridgeCallee
func (h *Holochain) BuildBridgeToCallee(app *BridgeApp) (err error) {

data := map[string]string{"Type": "ToCallee", "DNA": h.DNAHash().String(), "Data": app.BridgeGenesisDataTo}
data := map[string]string{"Type": "ToCallee", "DNA": h.DNAHash().String(), "Data": app.BridgeGenesisCalleeData}
dataJSON, err := json.Marshal(data)
if err != nil {
return
Expand Down Expand Up @@ -287,7 +287,7 @@ func (h *Holochain) BuildBridgeToCallee(app *BridgeApp) (err error) {
h.Debugf("%s received token %s from %s\n", h.Name(), token, app.Name)

// the url is currently through the webserver
err = h.AddBridgeAsCaller(app.BridgeZome, app.DNA, token, fmt.Sprintf("http://localhost:%s", app.Port), app.BridgeGenesisDataFrom)
err = h.AddBridgeAsCaller(app.BridgeZome, app.DNA, token, fmt.Sprintf("http://localhost:%s", app.Port), app.BridgeGenesisCallerData)
if err != nil {
h.Debugf("adding bridge to callee %s from %s failed with %s\n", app.Name, h.Name(), err)
return
Expand Down Expand Up @@ -318,9 +318,9 @@ func (h *Holochain) GetBridges() (bridges []Bridge, err error) {
if err != nil {
return false
}
bridges = append(bridges, Bridge{ToApp: hash, Side: BridgeFrom})
bridges = append(bridges, Bridge{ToApp: hash, Side: BridgeCaller})
case "tok":
bridges = append(bridges, Bridge{Token: x[1], Side: BridgeTo})
bridges = append(bridges, Bridge{Token: x[1], Side: BridgeCallee})
}
return true
})
Expand Down
4 changes: 2 additions & 2 deletions bridge_test.go
Expand Up @@ -133,9 +133,9 @@ func TestBridgeGetBridges(t *testing.T) {
Convey("it should return the bridged apps", t, func() {
bridges, err := h.GetBridges()
So(err, ShouldBeNil)
So(bridges[0].Side, ShouldEqual, BridgeFrom)
So(bridges[0].Side, ShouldEqual, BridgeCaller)
So(bridges[0].ToApp.String(), ShouldEqual, "QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw")
So(bridges[1].Side, ShouldEqual, BridgeTo)
So(bridges[1].Side, ShouldEqual, BridgeCallee)
So(bridges[1].Token, ShouldNotEqual, 0)
})
}
34 changes: 17 additions & 17 deletions cmd/hcadmin/hcadmin.go
Expand Up @@ -23,12 +23,12 @@ func setupApp() (app *cli.App) {
app = cli.NewApp()
app.Name = "hcadmin"
app.Usage = "holochain administration tool"
app.Version = fmt.Sprintf("0.0.3 (holochain %s)", holo.VersionStr)
app.Version = fmt.Sprintf("0.0.4 (holochain %s)", holo.VersionStr)

var dumpChain, dumpDHT, json bool
var root string
var service *holo.Service
var bridgeToAppData, bridgeFromAppData string
var bridgeCalleeAppData, bridgeCallerAppData string

app.Flags = []cli.Flag{
cli.BoolFlag{
Expand Down Expand Up @@ -178,47 +178,47 @@ func setupApp() (app *cli.App) {
{
Name: "bridge",
Aliases: []string{"b"},
ArgsUsage: "from-chain to-chain bridge-zome",
Usage: "allows to-chain to make calls to functions in from-chain",
ArgsUsage: "caller-chain callee-chain bridge-zome",
Usage: "allows caller-chain to make calls to functions in callee-chain",
Flags: []cli.Flag{
cli.StringFlag{
Name: "bridgeToAppData",
Usage: "application data to pass to the bridged to app",
Destination: &bridgeToAppData,
Name: "bridgeCalleeAppData",
Usage: "application data to pass to the bridged callee app",
Destination: &bridgeCalleeAppData,
},
cli.StringFlag{
Name: "bridgeFromAppData",
Usage: "application data to pass to the bridging from app",
Destination: &bridgeFromAppData,
Name: "bridgeCallerAppData",
Usage: "application data to pass to the bridging caller app",
Destination: &bridgeCallerAppData,
},
},
Action: func(c *cli.Context) error {
if len(c.Args()) != 3 {
return errors.New("bridge: requires three arguments: from-chain to-chain bridge-zome")
}
fromChain := c.Args()[0]
toChain := c.Args()[1]
callerChain := c.Args()[0]
calleeChain := c.Args()[1]
bridgeZome := c.Args()[2]

hFrom, err := cmd.GetHolochain(fromChain, service, "bridge")
hCaller, err := cmd.GetHolochain(callerChain, service, "bridge")
if err != nil {
return err
}
hTo, err := cmd.GetHolochain(toChain, service, "bridge")
hCallee, err := cmd.GetHolochain(calleeChain, service, "bridge")
if err != nil {
return err
}

token, err := hTo.AddBridgeAsCallee(hFrom.DNAHash(), bridgeToAppData)
token, err := hCallee.AddBridgeAsCallee(hCaller.DNAHash(), bridgeCalleeAppData)
if err != nil {
return err
}

err = hFrom.AddBridgeAsCaller(bridgeZome, hTo.DNAHash(), token, fmt.Sprintf("http://localhost:%d", hTo.Config.DHTPort), bridgeFromAppData)
err = hCaller.AddBridgeAsCaller(bridgeZome, hCallee.DNAHash(), token, fmt.Sprintf("http://localhost:%d", hCallee.Config.DHTPort), bridgeCallerAppData)

if err == nil {
if verbose {
fmt.Printf("bridge from %s to %s\n", fromChain, toChain)
fmt.Printf("bridge from %s to %s\n", callerChain, calleeChain)
}
}
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/hcadmin/hcadmin_test.go
Expand Up @@ -178,7 +178,7 @@ func TestBridge(t *testing.T) {

Convey("it should bridge chains", t, func() {
app = setupApp()
out, err := runAppWithStdoutCapture(app, []string{"hcadmin", "-debug", "-path", d, "bridge", "testApp1", "testApp2", "jsSampleZome", "-bridgeToAppData", "some to app data"})
out, err := runAppWithStdoutCapture(app, []string{"hcadmin", "-debug", "-path", d, "bridge", "testApp1", "testApp2", "jsSampleZome", "-bridgeCalleeAppData", "some to app data"})
So(err, ShouldBeNil)
So(out, ShouldContainSubstring, "bridge genesis to-- other side is:"+testApp1DNA+" bridging data:some to app data\n")
})
Expand Down
22 changes: 10 additions & 12 deletions cmd/hcdev/hcdev.go
Expand Up @@ -28,8 +28,6 @@ import (

const (
defaultUIPort = "4141"
bridgeFromPort = "21111"
bridgeToPort = "21112"
scenarioStartDelay = 1

defaultSpecsFile = "bridge_specs.json"
Expand Down Expand Up @@ -1052,12 +1050,12 @@ func getHolochain(c *cli.Context, service *holo.Service, identity string) (h *ho

// BridgeSpec describes an app to be bridged for dev
type BridgeSpec struct {
Path string // path to the app to bridge to/from
Side int // what side of the bridge the dev app is
BridgeGenesisDataFrom string // genesis data for the from side
BridgeGenesisDataTo string // genesis data for the to side
Port string // only used if side == BridgeTo
BridgeZome string // only used if side == BridgeFrom
Path string // path to the app to bridge to/from
Side int // what side of the bridge the dev app is (Bridge.Caller or Bridge.Callee)
BridgeGenesisCallerData string // genesis data for the caller side
BridgeGenesisCalleeData string // genesis data for the callee side
Port string // only used if side == BridgeCallee
BridgeZome string // only used if side == BridgeCaller
}

// getBridgeAppsForTests builds up an array of bridged apps based on the dev values for bridging
Expand Down Expand Up @@ -1091,10 +1089,10 @@ func getBridgeAppForTests(service *holo.Service, agent holo.Agent) (bridgedApps
Name: h.Name(),
DNA: h.DNAHash(),
Side: spec.Side,
BridgeGenesisDataFrom: spec.BridgeGenesisDataFrom,
BridgeGenesisDataTo: spec.BridgeGenesisDataTo,
Port: spec.Port,
BridgeZome: spec.BridgeZome,
BridgeGenesisCallerData: spec.BridgeGenesisCallerData,
BridgeGenesisCalleeData: spec.BridgeGenesisCalleeData,
Port: spec.Port,
BridgeZome: spec.BridgeZome,
},
})
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/hcdev/hcdev_test.go
Expand Up @@ -341,7 +341,7 @@ func TestBridging(t *testing.T) {

// bridging to ourselves for this test, so write out a bridgeSpecFile to use
bridgeSourceDir := filepath.Join(tmpTestDir, "bar")
data := []BridgeSpec{BridgeSpec{Path: bridgeSourceDir, Side: holo.BridgeTo, BridgeZome: "jsSampleZome", BridgeGenesisDataTo: "some data 314"}}
data := []BridgeSpec{BridgeSpec{Path: bridgeSourceDir, Side: holo.BridgeCallee, BridgeZome: "jsSampleZome", BridgeGenesisCalleeData: "some data 314"}}
var b bytes.Buffer
err := holo.Encode(&b, "json", data)

Expand Down Expand Up @@ -371,22 +371,22 @@ func TestSaveBridgeApps(t *testing.T) {
BridgeApp: holo.BridgeApp{
Name: "red fish",
DNA: hashRed,
Side: holo.BridgeFrom,
BridgeGenesisDataFrom: "data red from",
BridgeGenesisDataTo: "data blue to",
Port: "1234",
BridgeZome: "redzome",
Side: holo.BridgeCaller,
BridgeGenesisCallerData: "data red from",
BridgeGenesisCalleeData: "data blue to",
Port: "1234",
BridgeZome: "redzome",
},
},
BridgeAppForTests{
BridgeApp: holo.BridgeApp{
Name: "blue fish",
DNA: hashBlue,
Side: holo.BridgeTo,
BridgeGenesisDataFrom: "data red from",
BridgeGenesisDataTo: "data blue to",
Port: "4321",
BridgeZome: "bluezome",
Side: holo.BridgeCallee,
BridgeGenesisCallerData: "data red from",
BridgeGenesisCalleeData: "data blue to",
Port: "4321",
BridgeZome: "bluezome",
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions holochain.go
Expand Up @@ -30,10 +30,10 @@ import (

const (
// Version is the numeric version number of the holochain library
Version int = 23
Version int = 24

// VersionStr is the textual version number of the holochain library
VersionStr string = "23"
VersionStr string = "24"

// DefaultSendTimeout a time.Duration to wait by default for send to complete
DefaultSendTimeout = 3000 * time.Millisecond
Expand Down
6 changes: 3 additions & 3 deletions jsribosome.go
Expand Up @@ -336,8 +336,8 @@ const (
`,Full:` + PkgReqChainOptFullStr +
"}" +
"}" +
`,Bridge:{From:` + BridgeFromStr +
`,To:` + BridgeToStr +
`,Bridge:{Caller:` + BridgeCallerStr +
`,Callee:` + BridgeCalleeStr +
"}" +
`,BundleCancel:{` +
`Reason:{UserCancel:"` + BundleCancelReasonUserCancel +
Expand Down Expand Up @@ -650,7 +650,7 @@ func NewJSRibosome(h *Holochain, zome *Zome) (n Ribosome, err error) {
if i > 0 {
code += ","
}
if b.Side == BridgeTo {
if b.Side == BridgeCallee {
code += fmt.Sprintf(`{Side:%d,Token:"%s"}`, b.Side, b.Token)
} else {
code += fmt.Sprintf(`{Side:%d,ToApp:"%s"}`, b.Side, b.ToApp.String())
Expand Down

0 comments on commit 5067e8b

Please sign in to comment.