Skip to content

Commit

Permalink
Improve support for multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Andersen committed Oct 4, 2018
1 parent a07892d commit 3b84128
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 24 deletions.
16 changes: 12 additions & 4 deletions cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,17 @@ func actionMkEntity(c *cli.Context) error {
os.Exit(1)
}
}
var revloc *pb.Location
if c.String("revocationlocation") != "" {
revloc = &pb.Location{
AgentLocation: c.String("revocationlocation"),
}
}
resp, err := conn.CreateEntity(context.Background(), &pb.CreateEntityParams{
ValidFrom: time.Now().UnixNano() / 1e6,
ValidUntil: time.Now().Add(*expiry).UnixNano() / 1e6,
SecretPassphrase: string(pass),
ValidFrom: time.Now().UnixNano() / 1e6,
ValidUntil: time.Now().Add(*expiry).UnixNano() / 1e6,
SecretPassphrase: string(pass),
RevocationLocation: revloc,
})
if err != nil {
fmt.Printf("error: %v\n", err)
Expand All @@ -126,7 +133,8 @@ func actionMkEntity(c *cli.Context) error {
fmt.Printf("wrote entity: %s\n", filename)
if !c.Bool("nopublish") {
presp, err := conn.PublishEntity(context.Background(), &pb.PublishEntityParams{
DER: resp.PublicDER,
DER: resp.PublicDER,
Location: revloc,
})
if err != nil {
fmt.Printf("publish error: %v\n", err)
Expand Down
24 changes: 10 additions & 14 deletions storage/testbench/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
)

//Modify this to instantiate the storage provider you want to test:
func getInstance(t *testing.T) iapi.StorageDriverInterface {
func getInstance(t testing.TB) iapi.StorageDriverInterface {
return getSimpleHTTPStorageInstance(t)
}

var storageconfig map[string]string

func getSimpleHTTPStorageInstance(t *testing.T) iapi.StorageDriverInterface {
func getSimpleHTTPStorageInstance(t testing.TB) iapi.StorageDriverInterface {
sh := &simplehttp.SimpleHTTPStorage{}
require.NoError(t, sh.Initialize(context.Background(), "simplehttp", storageconfig))
return sh
Expand All @@ -43,14 +43,10 @@ func getSimpleHTTPStorageInstance(t *testing.T) iapi.StorageDriverInterface {
func init() {
storageconfig = make(map[string]string)
storageconfig["provider"] = "http_v1"
storageconfig["url"] = "http://127.0.0.1:8080/v1"
storageconfig["url"] = "https://vldm.storage.bwave.io/v1"
storageconfig["v1key"] = `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKG6NaA54Fx6m7Ih019r1LDXDf7ay
CQKL0D2lvjF0TcQP8Kx+lFrRyjvqBJrrv5KUPcbBYWXJwscLTDkwA3zBtg==
-----END PUBLIC KEY-----`
storageconfig["v1certifiers"] = `-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEjxdbNOQuEkIhfN61raSYgijjygMf
uVBgJsnNrDbraLaHGzbbrYX1BoDm9BomJHSSQpeOYTabcdQ9Jy9n8v45oA==
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEwo6w0SSVDM/EXPDFKpogJYtjDDZp
s+QeDH7bL1HJuTOekmC/Ry1xcSXPTr1/WfywTdT6N1MmYdmz3EXaLJbsJA==
-----END PUBLIC KEY-----`
storageconfig["v1auditors"] = "127.0.0.1:5001"
cfg := make(map[string]map[string]string)
Expand Down Expand Up @@ -245,7 +241,7 @@ func TestEnqueDequeueDelay(t *testing.T) {

func BenchmarkPut2KB(b *testing.B) {
body := make([]byte, 2000)
in := getInstance(nil)
in := getInstance(b)
rand.Read(body)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand All @@ -256,7 +252,7 @@ func BenchmarkPut2KB(b *testing.B) {

func BenchmarkGet2KB(b *testing.B) {
body := make([]byte, 2000)
in := getInstance(nil)
in := getInstance(b)
rand.Read(body)
resp, _ := in.Put(context.Background(), body)
b.ResetTimer()
Expand All @@ -267,7 +263,7 @@ func BenchmarkGet2KB(b *testing.B) {

func BenchmarkGet2KBDelay(b *testing.B) {
body := make([]byte, 2000)
in := getInstance(nil)
in := getInstance(b)
rand.Read(body)
resp, _ := in.Put(context.Background(), body)
time.Sleep(5 * time.Second)
Expand All @@ -284,7 +280,7 @@ func BenchmarkEnqueue(b *testing.B) {
other := make([]byte, 32)
rand.Read(other)
valhash := iapi.KECCAK256.Instance(other)
in := getInstance(nil)
in := getInstance(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
in.Enqueue(context.Background(), hash, valhash)
Expand All @@ -298,7 +294,7 @@ func BenchmarkDequeue(b *testing.B) {
other := make([]byte, 32)
rand.Read(other)
valhash := iapi.KECCAK256.Instance(other)
in := getInstance(nil)
in := getInstance(b)
in.Enqueue(context.Background(), hash, valhash)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
15 changes: 13 additions & 2 deletions storage/vldmstorage3/server/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"sync"

_ "github.com/go-sql-driver/mysql"
"github.com/go-sql-driver/mysql"
"github.com/samkumar/reqcache"
)

Expand Down Expand Up @@ -53,6 +53,8 @@ func (d *db) getobject(ctx context.Context, key interface{}) (interface{}, uint6
return value, 1, nil
}

var ErrAlreadyExists = errors.New("Already exists\n")

func (d *db) InsertObject(hash []byte, object []byte) error {
k := base64.URLEncoding.EncodeToString(hash)
d.lru.Put(k, object, 1)
Expand All @@ -62,7 +64,16 @@ func (d *db) InsertObject(hash []byte, object []byte) error {
}
_, err = tx.Exec("INSERT INTO ValueMapping (Hash, Value) VALUES (?, ?)", k, object)
if err != nil {
panic(err)
me, ok := err.(*mysql.MySQLError)
if !ok {
panic(err)
}
if me.Number == 1062 {
//Record already existed
return ErrAlreadyExists
} else {
panic(err)
}
}
err = tx.Commit()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion storage/vldmstorage3/server/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ func main() {
go grpcServer.Serve(l)

http.Handle("/", r)
err = http.ListenAndServe(":8080", nil)
//err = http.ListenAndServe(":8080", nil)
err = http.ListenAndServeTLS(":443", "certpublic", "certprivate", nil)
panic(err)
}
8 changes: 6 additions & 2 deletions storage/vldmstorage3/server/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,22 @@ func PerformOneMap(certifierIDs []string) (bool, error) {
}

endID := startEntry

included := make(map[string]bool)
for _, l := range entryresp.Leaves {
mp := &PromiseObject{}
err := json.Unmarshal(l.LeafValue, &mp)
if err != nil {
panic(err)
}
endID = l.LeafIndex
if included[string(mp.Key)] {
continue
}
setReq.Leaves = append(setReq.Leaves, &trillian.MapLeaf{
Index: mp.Key,
LeafValue: mp.Value,
})
endID = l.LeafIndex
included[string(mp.Key)] = true
}
mapperMetadata.HighestFullyCompletedSeq = endID

Expand Down
16 changes: 15 additions & 1 deletion waved/cmd/wave.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ database = "/var/lib/wave/db"
# This should ideally be below 1000 to prevent a non root service
# from binding to this port
listenIp = "127.0.0.1:410"
httpListenIp = "127.0.0.1:411"

# If you cannot reach storage, is the entity revoked or not?
defaultToUnrevoked = false

[storage]
# This is the default HTTPS server until we get AWS/Azure


# This is the default development server
[storage.default]
provider = "http_v1"
url = "https://standalone.storage.bwave.io/v1"
version = "1"

[storage.vldm]
provider = "http_v1"
url = "https://vldm.storage.bwave.io/v1"
v1key = """-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEwo6w0SSVDM/EXPDFKpogJYtjDDZp
s+QeDH7bL1HJuTOekmC/Ry1xcSXPTr1/WfywTdT6N1MmYdmz3EXaLJbsJA==
-----END PUBLIC KEY-----"""
8 changes: 8 additions & 0 deletions waved/wave.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ defaultToUnrevoked = false
provider = "http_v1"
url = "https://standalone.storage.bwave.io/v1"
version = "1"

[storage.vldm]
provider = "http_v1"
url = "https://vldm.storage.bwave.io/v1"
v1key = """-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEwo6w0SSVDM/EXPDFKpogJYtjDDZp
s+QeDH7bL1HJuTOekmC/Ry1xcSXPTr1/WfywTdT6N1MmYdmz3EXaLJbsJA==
-----END PUBLIC KEY-----"""

0 comments on commit 3b84128

Please sign in to comment.