Skip to content

Commit

Permalink
Moving out the config reading into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
nikirill committed Feb 24, 2021
1 parent a7fae83 commit 33a4118
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/lukechampine/fastxor v0.0.0-20200124170337-07dbf569dfe7
github.com/nikirill/go-crypto v0.0.0-20210204153324-694bf46cc691
github.com/stretchr/testify v1.7.0
github.com/wealdtech/go-merkletree v1.0.0 // indirect
github.com/wealdtech/go-merkletree v1.0.0
gitlab.com/NebulousLabs/merkletree v0.0.0-20200118113624-07fbf710afc4 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
Expand Down
31 changes: 18 additions & 13 deletions simulations/simul.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,16 @@ func main() {
log.Printf("config file %s", *indivConfigFile)

// load simulation's config files
var err error
genConfig := new(generalParam)
_, err = toml.DecodeFile(generalConfigFile, genConfig)
if err != nil {
log.Fatal(err)
}
indConfig := new(individualParam)
_, err = toml.DecodeFile(*indivConfigFile, indConfig)
s, err := loadSimulationConfigs(generalConfigFile, *indivConfigFile)
if err != nil {
log.Fatal(err)
}
s := &Simulation{generalParam: *genConfig, individualParam: *indConfig}

log.Printf("running simulation %#v\n", s)

// check simulation
if !s.validSimulation() {
panic("invalid simulation")
log.Fatal("invalid simulation")
}

log.Printf("running simulation %#v\n", s)
// initialize experiment
experiment := &Experiment{Results: make(map[int][]*Chunk, 0)}

Expand Down Expand Up @@ -275,6 +265,21 @@ func makePIRDPFServers(db *database.Bytes) []server.Server {
return []server.Server{s0, s1}
}

func loadSimulationConfigs(genFile, indFile string) (*Simulation, error) {
var err error
genConfig := new(generalParam)
_, err = toml.DecodeFile(genFile, genConfig)
if err != nil {
return nil, err
}
indConfig := new(individualParam)
_, err = toml.DecodeFile(indFile, indConfig)
if err != nil {
return nil, err
}
return &Simulation{generalParam: *genConfig, individualParam: *indConfig}, nil
}

func (s *Simulation) validSimulation() bool {
return s.Primitive == "vpir-it" || s.Primitive == "vpir-dpf" || s.Primitive == "pir-it" || s.Primitive == "pir-dpf"
}

0 comments on commit 33a4118

Please sign in to comment.