Skip to content

Commit

Permalink
set multi optional submodes
Browse files Browse the repository at this point in the history
  • Loading branch information
10to4 committed Jun 10, 2019
1 parent ee4f1e5 commit 9e737ae
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
51 changes: 34 additions & 17 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@ func ReLoadConfigAPIHandler(w http.ResponseWriter, r *http.Request) {
}

type PublishExtraInfo struct {
MerkleRoot string `json:"mklroot"`
Mode string `json:"mode"`
SubMode string `json:"sub_mode"`
UnitPrice int64 `json:"uprice"`
Description string `json:"description"`
ContractAddr string `json:"contract_addr"`
MerkleRoot string `json:"mklroot"`
Mode string `json:"mode"`
SubMode []string `json:"sub_mode"`
UnitPrice int64 `json:"uprice"`
Description string `json:"description"`
ContractAddr string `json:"contract_addr"`
}

type InitPublishConfig struct {
Mode string `json:"mode"`
SubMode string `json:"sub_mode"`
Column string `json:"column"`
Keys []int `json:"keys"`
UnitPrice int64 `json:"unit_price"`
Description string `json:"description"`
FilePath string `json:"file_path"`
Mode string `json:"mode"`
SubMode []string `json:"sub_mode"`
Column string `json:"column"`
Keys []int `json:"keys"`
UnitPrice int64 `json:"unit_price"`
Description string `json:"description"`
FilePath string `json:"file_path"`
}

//InitPublishDataAPIHandler is a api handler for seller to initializing data for publishing.
Expand Down Expand Up @@ -202,12 +202,29 @@ func InitPublishDataAPIHandler(w http.ResponseWriter, r *http.Request) {
return
}

if (config.Mode == "plain" && (config.SubMode == "table1" || config.SubMode == "table2") && config.Column != "") ||
(config.Mode == "table" && (config.SubMode == "table1" || config.SubMode == "table2" || config.SubMode == "vrf") && len(config.Keys) != 0) {
Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)
if len(config.SubMode) == 0 {
Log.Warnf("parameters are incomplete, submode is nil. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)
fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM)
return
}

if config.Mode == TRANSACTION_MODE_PLAIN_POD {
for _, s := range config.SubMode {
if s != TRANSACTION_SUB_MODE_BATCH1 && s != TRANSACTION_SUB_MODE_BATCH2 {
Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)
fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM)
return
}
}
} else if config.Mode == TRANSACTION_MODE_TABLE_POD {
for _, s := range config.SubMode {
if s != TRANSACTION_SUB_MODE_BATCH1 && s != TRANSACTION_SUB_MODE_BATCH2 && s != TRANSACTION_SUB_MODE_VRF {
Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)
fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM)
return
}
}
}
Log.Debugf("parameter verified. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)
plog.Detail = fmt.Sprintf("mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys)

Expand Down Expand Up @@ -621,7 +638,7 @@ func BuyerPurchaseDataAPIHandler(w http.ResponseWriter, r *http.Request) {
plog.Detail = fmt.Sprintf("%v, merkle root=%v,", plog.Detail, bulletin.SigmaMKLRoot)

Log.Debugf("step0: prepare for transaction...")
var params = BuyerConnParam{data.SellerIP, data.SellerAddr, bulletin.Mode, "", data.OT, data.UnitPrice, "", bulletin.SigmaMKLRoot}
var params = BuyerConnParam{data.SellerIP, data.SellerAddr, bulletin.Mode, data.SubMode, data.OT, data.UnitPrice, "", bulletin.SigmaMKLRoot}
node, conn, params, err := preBuyerConn(params, ETHKey, Log)
if err != nil {
Log.Warnf("failed to prepare net for transaction. err=%v", err)
Expand Down
2 changes: 1 addition & 1 deletion buyer_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func buyerTxForPB2(node *pod_net.Node, key *keystore.Key, tx BuyerTransaction, d
tx.Status = TRANSACTION_STATUS_VERIFY_FAILED
return fmt.Sprintf(RESPONSE_TRANSACTION_FAILED, "step1: failed to purchase data.")
} else {
Log.Warnf("[%v]step6: start decrypt data...", tx.SessionID)
Log.Debugf("[%v]step6: start decrypt data...", tx.SessionID)
rs = tx.PlainBatch2.buyerDecrypt(outputFile, Log)
if !rs {
tx.Status = TRANSACTION_STATUS_DECRYPT_FAILED
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RequestData struct {
PubPath string `json:"pub_path"`
BulletinFile string `json:"bulletin_file"`
// Mode string `json:"mode"`
// SubMode string `json:"sub_mode"`
SubMode string `json:"sub_mode"`
OT bool `json:"ot"`
Demands []Demand `json:"demands"`
Phantoms []Phantom `json:"phantoms"`
Expand Down
17 changes: 15 additions & 2 deletions seller_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,22 @@ func preSellerTx(mklroot string, re requestExtra, Log ILogger) (SellerConnParam,
}
params.UnitPrice = re.Price
re.Mode = bulletin.Mode
re.SubMode = extra.SubMode
var subMode string
if len(extra.SubMode) == 0 {
return params, re, fmt.Errorf("no subMode")
}
for _, s := range extra.SubMode {
if re.SubMode == s && s != "" {
subMode = s
break
}
}
if subMode == "" {
subMode = extra.SubMode[0]
}
re.SubMode = subMode
params.Mode = bulletin.Mode
params.SubMode = extra.SubMode
params.SubMode = subMode
if params.SubMode == TRANSACTION_SUB_MODE_BATCH2 {
re.Ot = false
}
Expand Down

0 comments on commit 9e737ae

Please sign in to comment.