privacylab / talek

a Private Publish Subscribe System
BSD 2-Clause "Simplified" License
48 stars 5 forks source link

talekutil --common output is missing common.Config section #94

Closed mixmasala closed 8 months ago

mixmasala commented 1 year ago

For some reason the json serialization of server.Config doesn't include common.Config:

        if *outputCommon {
                com := common.Config{
                        NumBuckets:         1024,
                        BucketDepth:        4,
                        DataSize:           1024,
                        BloomFalsePositive: .05,
                        WriteInterval:      time.Second,
                        ReadInterval:       time.Second,
                        InterestMultiple:   10,
                        InterestSeed:       int64(rand.Uint64()),
                        MaxLoadFactor:      0.95,
                        LoadFactorStep:     0.05,
                }
                sc := server.Config{
                        ReadBatch:     8,
                        WriteInterval: time.Second,
                        ReadInterval:  time.Second,
                        Config: &com,
                }

                commonDat, err := json.MarshalIndent(sc, "", "  ")
                               if err != nil {
                        fmt.Printf("Could not serialize common config: %v\n", err)
                        return
                }
                ioutil.WriteFile(*outfile, commonDat, 0640)

                return
        }

The file written to outfile doesn't contain the Config section key, however:

 go build && ./talekutil --common  && cat talek.json
{
  "ReadBatch": 8,
  "WriteInterval": "1000000000",
  "ReadInterval": "1000000000",
  "TrustDomain": null,
  "TrustDomainIndex": 0
}

Not sure why this occurs.

mixmasala commented 1 year ago

So it looks lik the json decoder is instructed to skip the inherited common.Config fields. I think the fix looks like this:

diff --git a/server/config.go b/server/config.go
index eea7a20..67a2e6b 100644
--- a/server/config.go
+++ b/server/config.go
@@ -11,7 +11,7 @@ import (
 // Config represents the configuration needed to start a Talek server.
 // configurations can be generated through util/talekutil
 type Config struct {
-   *common.Config `json:"-"`
+   *common.Config

    // How many read requests should be made of the PIR server at a time?
    ReadBatch int

And then usage is like so:

185418d0a9ae:/build/talek/cli/talekutil# rm *.json
185418d0a9ae:/build/talek/cli/talekutil# go build && ./talekutil  --common --outfile common.json
185418d0a9ae:/build/talek/cli/talekutil# ./talekutil --incommon common.json  --replica --outfile replica.json
185418d0a9ae:/build/talek/cli/talekutil# cd ../talekreplica/
185418d0a9ae:/build/talek/cli/talekreplica# ./talekreplica -f ../talekutil/common.json -c ../talekutil/replica.json 
2023-07-26 12:29:15.271544 I | ---------------------
2023-07-26 12:29:15.271959 I | --- Talek Replica ---
2023-07-26 12:29:15.271984 I | ---------------------
2023-07-26 12:29:15.272096 I | Arguments:
2023-07-26 12:29:15.272125 I | config=../talekutil/replica.json
2023-07-26 12:29:15.272146 I | backing=cpu.0
2023-07-26 12:29:15.273472 I | Using the following configuration:
2023-07-26 12:29:15.273578 I | serverConfig=server.Config{Config:(*common.Config)(0xc0000e61e0), ReadBatch:8, WriteInterval:1000000000, ReadInterval:1000000000, TrustDomain:(*common.TrustDomainConfig)(0xc000110750), TrustDomainIndex:0}
2023-07-26 12:29:15.273655 I | serverConfig.Config=&common.Config{NumBuckets:0x400, BucketDepth:0x4, DataSize:0x400, BloomFalsePositive:0.042, WriteInterval:1000000000, ReadInterval:1000000000, InterestMultiple:0xa, InterestSeed:5577006791947779410, MaxLoadFactor:0.95, LoadFactorStep:0.05}
[CPU Shard (cpu.0)] INFO: 2023/07/26 12:29:15 shard_cpu.go:76: NewShardCPU(CPU Shard (cpu.0)) finished
2023-07-26 12:29:15.299724 I | Running.
mixmasala commented 1 year ago

But note that doing this puts the common.Config fields into the server.Config, so it isn't really necessary to have a separate common.Config file. Thoughts? I'm not very familiar with this project so I'm not sure what the intent was.

willscott commented 1 year ago

i think common config was separate because since it's shared / global that file would be put publicly / also provided to clients, while the rest of server config is specific to a given server operator.

mixmasala commented 9 months ago

I can c

So it looks lik the json decoder is instructed to skip the inherited common.Config fields. I think the fix looks like this:

diff --git a/server/config.go b/server/config.go
index eea7a20..67a2e6b 100644
--- a/server/config.go
+++ b/server/config.go
@@ -11,7 +11,7 @@ import (
 // Config represents the configuration needed to start a Talek server.
 // configurations can be generated through util/talekutil
 type Config struct {
- *common.Config `json:"-"`
+ *common.Config

  // How many read requests should be made of the PIR server at a time?
  ReadBatch int

And then usage is like so:

185418d0a9ae:/build/talek/cli/talekutil# rm *.json
185418d0a9ae:/build/talek/cli/talekutil# go build && ./talekutil  --common --outfile common.json
185418d0a9ae:/build/talek/cli/talekutil# ./talekutil --incommon common.json  --replica --outfile replica.json
185418d0a9ae:/build/talek/cli/talekutil# cd ../talekreplica/
185418d0a9ae:/build/talek/cli/talekreplica# ./talekreplica -f ../talekutil/common.json -c ../talekutil/replica.json 
2023-07-26 12:29:15.271544 I | ---------------------
2023-07-26 12:29:15.271959 I | --- Talek Replica ---
2023-07-26 12:29:15.271984 I | ---------------------
2023-07-26 12:29:15.272096 I | Arguments:
2023-07-26 12:29:15.272125 I | config=../talekutil/replica.json
2023-07-26 12:29:15.272146 I | backing=cpu.0
2023-07-26 12:29:15.273472 I | Using the following configuration:
2023-07-26 12:29:15.273578 I | serverConfig=server.Config{Config:(*common.Config)(0xc0000e61e0), ReadBatch:8, WriteInterval:1000000000, ReadInterval:1000000000, TrustDomain:(*common.TrustDomainConfig)(0xc000110750), TrustDomainIndex:0}
2023-07-26 12:29:15.273655 I | serverConfig.Config=&common.Config{NumBuckets:0x400, BucketDepth:0x4, DataSize:0x400, BloomFalsePositive:0.042, WriteInterval:1000000000, ReadInterval:1000000000, InterestMultiple:0xa, InterestSeed:5577006791947779410, MaxLoadFactor:0.95, LoadFactorStep:0.05}
[CPU Shard (cpu.0)] INFO: 2023/07/26 12:29:15 shard_cpu.go:76: NewShardCPU(CPU Shard (cpu.0)) finished
2023-07-26 12:29:15.299724 I | Running.

This does fix the serialization issue. There is a similar issue with libtalek.ClientConfig - where cli/talekclient needs the common.Config fields, so serializing a ClientConfig to json doesn't produce a usable config. See #95

willscott commented 8 months ago

fixed with #95