Skip to content

Commit

Permalink
Progress is great
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Andersen committed Jun 3, 2015
1 parent 2d8e725 commit b69831a
Show file tree
Hide file tree
Showing 9 changed files with 576 additions and 176 deletions.
26 changes: 17 additions & 9 deletions adapter/oob/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -84,17 +85,23 @@ func (a *Adapter) handleClient(conn net.Conn) {
}
}

func loadCommonURI(f *objects.Frame) ([]byte, string, bool) {
func loadCommonURI(f *objects.Frame, bw *api.BW) ([]byte, string, bool) {
mvk, mvkOk := f.GetFirstHeader("mvk")
var rmvk []byte
uri, uriOk := f.GetFirstHeader("uri")
suffix, suffixOk := f.GetFirstHeader("uri_suffix")
if uriOk {
var ok bool
rmvk, suffix, ok = api.SplitURI(uri)
if !ok {
var err error
parts := strings.SplitN(uri, "/", 2)
if len(parts) != 2 {
return nil, "", false
}
rmvk, err = bw.ResolveName(parts[0])
if err != nil {
log.Info("Could not resolve uri: " + parts[0] + ":" + err.Error())
return nil, "", false
}
suffix = parts[1]
} else if !(mvkOk && suffixOk) {
return nil, "", false
} else {
Expand Down Expand Up @@ -221,7 +228,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
}
switch f.Cmd {
case objects.CmdPublish, objects.CmdPersist:
mvk, suffix, ok := loadCommonURI(f)
mvk, suffix, ok := loadCommonURI(f, bwcl.BW())
if !ok {
err("malformed URI components")
return
Expand Down Expand Up @@ -267,7 +274,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
bwcl.Publish(p, mkGenericActionCB(replyto, send))
return
case objects.CmdList:
mvk, suffix, ok := loadCommonURI(f)
mvk, suffix, ok := loadCommonURI(f, bwcl.BW())
if !ok {
err("malformed URI components")
return
Expand Down Expand Up @@ -318,7 +325,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
}
unpack = cx
}
mvk, suffix, ok := loadCommonURI(f)
mvk, suffix, ok := loadCommonURI(f, bwcl.BW())
if !ok {
err("malformed URI components")
return
Expand Down Expand Up @@ -377,7 +384,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
}
unpack = cx
}
mvk, suffix, ok := loadCommonURI(f)
mvk, suffix, ok := loadCommonURI(f, bwcl.BW())
if !ok {
err("malformed URI components")
return
Expand Down Expand Up @@ -409,6 +416,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
}
bwcl.Subscribe(p,
func(status int, isNew bool, id core.UniqueMessageID, msg string) {
log.Infof("Got action CB for sub: %v %v %v", status, isNew, msg)
if status == core.BWStatusOkay {
r := objects.CreateFrame(objects.CmdResponse, replyto)
r.AddHeader("status", "okay")
Expand Down Expand Up @@ -556,7 +564,7 @@ func dispatchFrame(bwcl *api.BosswaveClient, f *objects.Frame, send func(f *obje
}

if !ispermission {
mvk, suffix, ok := loadCommonURI(f)
mvk, suffix, ok := loadCommonURI(f, bwcl.BW())
if !ok {
err("access DOTs require URI")
return
Expand Down
38 changes: 26 additions & 12 deletions api/async_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ type PublishCallback func(status int, msg string)

func (c *BosswaveClient) checkAddOriginVK(m *core.Message) {

if m.PrimaryAccessChain == nil ||
m.PrimaryAccessChain.GetReceiverVK() == nil ||
objects.IsEveryoneVK(m.PrimaryAccessChain.GetReceiverVK()) {
fmt.Println("Adding an origin VK header")
//Although the PAC may not be elaborated, we might be able to
//elaborate it some more here for our decision support
pac := m.PrimaryAccessChain
if pac != nil {
if !pac.IsElaborated() {
dc := core.ElaborateDChain(m.PrimaryAccessChain)
if dc != nil {
pac = dc
}
}
core.ResolveDotsInDChain(pac, nil)
}
if pac == nil || !pac.IsElaborated() ||
pac.GetReceiverVK() == nil ||
objects.IsEveryoneVK(pac.GetReceiverVK()) {
ovk := objects.CreateOriginVK(c.us.GetVK())
m.RoutingObjects = append(m.RoutingObjects, ovk)
vk := c.us.GetVK()
Expand Down Expand Up @@ -474,15 +485,18 @@ func (c *BosswaveClient) CreateEntity(p *CreateEntityParams) *objects.Entity {
func (c *BosswaveClient) doPAC(m *core.Message, elaboratePAC int) (int, string) {

//If there is no explicit PAC, use the first access chain in the ROs
if m.PrimaryAccessChain == nil {
for _, ro := range m.RoutingObjects {
if ro.GetRONum() == objects.ROAccessDChain ||
ro.GetRONum() == objects.ROAccessDChainHash {
m.PrimaryAccessChain = ro.(*objects.DChain)
break
//NOPE because sometimes you want to send access chains but not treat
//it as the PAC
/*
if m.PrimaryAccessChain == nil {
for _, ro := range m.RoutingObjects {
if ro.GetRONum() == objects.ROAccessDChain ||
ro.GetRONum() == objects.ROAccessDChainHash {
m.PrimaryAccessChain = ro.(*objects.DChain)
break
}
}
}
}
}*/
//Elaborate PAC
if elaboratePAC > NoElaboration {
if m.PrimaryAccessChain == nil {
Expand Down
9 changes: 6 additions & 3 deletions api/bosswave.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"net"
"os"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -70,7 +71,7 @@ func OpenBWContext(config *core.BWConfig) *BW {
os.Exit(1)
}
rv.Entity = objects.CreateLightEntity(rVK, rSK)
rv.MVKs = make([][]byte, len(config.Affinity.MVK))
rv.MVKs = make([][]byte, len(config.Affinity.MVK)+1)
for i, smvk := range config.Affinity.MVK {
mvk, err := crypto.UnFmtKey(smvk)
if err != nil {
Expand All @@ -79,6 +80,7 @@ func OpenBWContext(config *core.BWConfig) *BW {
}
rv.MVKs[i] = mvk
}
rv.MVKs[len(config.Affinity.MVK)] = rv.Entity.GetVK()
rocks.Initialize(config.Router.DB)
return rv
}
Expand Down Expand Up @@ -187,8 +189,9 @@ func (bw *BW) GetTarget(drvk string) (string, error) {
if len(addrs) < 1 {
return "", errors.New("Unable to resolve VK to router")
}
bw.Targetcache[drvk] = addrs[0].Target
return addrs[0].Target, nil
tgt := addrs[0].Target[:len(addrs[0].Target)-1] + ":" + strconv.Itoa(int(addrs[0].Port))
bw.Targetcache[drvk] = tgt
return tgt, nil
}
func (bw *BW) GetDRVK(mvk string) ([]byte, error) {
bw.cachelock.Lock()
Expand Down
Loading

0 comments on commit b69831a

Please sign in to comment.