# Copyright 2007 Kevin Reid under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") def makeBrand :DeepFrozen := def makeCapTPHub(makeConnection, outgoingConnect) implements ExitViaHere, DeepFrozen { def liveConnections := [].asMap().diverge() def [for3DescSealer, for3DescUnsealer] := makeBrand("CapTP 3Desc transfer") def for3DescBrand := for3DescSealer.getBrand() def connectAndRegister def get(searchPath, vatID) { return liveConnections.fetch(vatID, fn{ connectAndRegister(searchPath, vatID) liveConnections[vatID] }) } def register(searchPath, vatID, remoteRec) { var live := true def peerHub { to get(otherSearchPath, otherVatID) { return get(otherSearchPath, otherVatID)[1] } to nowDead() { if (live) { live := false liveConnections.removeKey(vatID) } } to get3DescBrand() { return for3DescBrand } to get3DescSealer() { return for3DescSealer } to amplifyFor3Desc(specimen, recipID) { if (for3DescUnsealer.amplify(specimen) =~ [wantsRecip]) { return wantsRecip(recipID) } } to isOurProxy(specimen) { return for3DescUnsealer.amplify(specimen) =~ [_] } } def [localRec, of, pf] := makeConnection(peerHub, searchPath, vatID, remoteRec) liveConnections[vatID] := [of, pf] return localRec } bind connectAndRegister(searchPath, vatID) { def localRec := register(searchPath, vatID, outgoingConnect(localRec, searchPath, vatID)) } def hubOutward { to get(searchPath, vatID) { return get(searchPath, vatID)[0] } to incoming(searchPath, vatID, remoteRec) { # XXX fail if connection already present return register(searchPath, vatID, remoteRec) } } return hubOutward }