本文整理匯總了Golang中github.com/apanda/smpc/proto.Action類的典型用法代碼示例。如果您正苦於以下問題:Golang Action類的具體用法?Golang Action怎麽用?Golang Action使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Action類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OneSub
func (state *ComputePeerState) OneSub(action *sproto.Action) *sproto.Response {
//fmt.Println("Subtraction one from value")
result := *action.Result
share0 := *action.Share0
share0val, hasShare0val := state.SharesGet(share0)
if hasShare0val {
val := core.Sub(1, share0val)
state.SharesSet(result, val)
}
return state.failResponse(action.GetRequestCode())
}
示例2: Add
// Add two shares
func (state *ComputePeerState) Add(action *sproto.Action) *sproto.Response {
//fmt.Println("Adding two values")
result := *action.Result
share0 := *action.Share0
share1 := *action.Share1
share0val, hasShare0val := state.SharesGet(share0)
share1val, hasShare1val := state.SharesGet(share1)
if hasShare0val && hasShare1val {
state.SharesSet(result, core.Add(share0val, share1val))
//fmt.Println("Done Adding")
return state.okResponse(action.GetRequestCode())
}
//fmt.Printf("Failed additions, response would have been %s (%s, %v, %s, %v)\n", result, share0, hasShare0val, share1, hasShare1val)
return state.failResponse(action.GetRequestCode())
}
示例3: Neqz
// Test inequality to zero
func (state *ComputePeerState) Neqz(action *sproto.Action) *sproto.Response {
//fmt.Println("Comparing values")
result := *action.Result
share0 := *action.Share0
share0val, hasShare0Val := state.SharesGet(share0)
rcode := *action.RequestCode
if !hasShare0Val {
//fmt.Printf("Failing, variable %s not found\n", share0)
return state.failResponse(action.GetRequestCode())
}
res := state.neqz(share0val, rcode)
state.SharesSet(result, res)
//fmt.Printf("Done testing value for not zero\n")
return state.okResponse(action.GetRequestCode())
}
示例4: GetValue
// Retrieve the value of a share
func (state *ComputePeerState) GetValue(action *sproto.Action) *sproto.Response {
result := *action.Result
val, hasVal := state.SharesGet(result)
if hasVal {
resp := &sproto.Response{}
rcode := action.GetRequestCode()
resp.RequestCode = &rcode
resp.Share = &val
status := sproto.Response_Val
resp.Status = &status
client := int32(state.Client)
resp.Client = &client
return resp
}
return state.failResponse(action.GetRequestCode())
}
示例5: MulConst
// Multiply const
func (state *ComputePeerState) MulConst(action *sproto.Action) *sproto.Response {
//fmt.Println("Multiplying with constants")
result := *action.Result
share0 := *action.Share0
val := *action.Value
share0val, hasShare0Val := state.SharesGet(share0)
rcode := *action.RequestCode
if !hasShare0Val {
//fmt.Printf("Failing, variable %s not found\n", share0)
return state.failResponse(action.GetRequestCode())
}
res := core.MultUnderMod(val, share0val)
state.SharesSet(result, res)
//fmt.Println("Done multiplying constants")
return state.okResponse(rcode)
}
示例6: Eqz
// Test equality to zero
func (state *ComputePeerState) Eqz(action *sproto.Action) *sproto.Response {
//fmt.Println("Comparing values")
result := *action.Result
share0 := *action.Share0
share0val, hasShare0Val := state.SharesGet(share0)
rcode := *action.RequestCode
if !hasShare0Val {
return state.failResponse(action.GetRequestCode())
}
res := state.neqz(share0val, rcode)
one := int64(1)
res = core.Sub(one, res)
state.SharesSet(result, res)
//fmt.Printf("Done testing value for zero\n")
return state.okResponse(action.GetRequestCode())
}
示例7: Neq
// Inequality
func (state *ComputePeerState) Neq(action *sproto.Action) *sproto.Response {
//fmt.Println("Comparing values")
result := *action.Result
share0 := *action.Share0
share1 := *action.Share1
share0val, hasShare0Val := state.SharesGet(share0)
share1val, hasShare1Val := state.SharesGet(share1)
rcode := *action.RequestCode
if !hasShare0Val || !hasShare1Val {
return state.failResponse(action.GetRequestCode())
}
res := state.ncmp(share0val, share1val, rcode)
state.SharesSet(result, res)
//fmt.Printf("Done comparing values\n")
return state.okResponse(action.GetRequestCode())
}
示例8: SetValue
// Set the value of a share
func (state *ComputePeerState) SetValue(action *sproto.Action) *sproto.Response {
//fmt.Println("Setting value ", *action.Result, *action.Value)
result := *action.Result
val := *action.Value
state.SharesSet(result, int64(val))
//fmt.Println("Returned from sharesset")
resp := &sproto.Response{}
rcode := action.GetRequestCode()
resp.RequestCode = &rcode
status := sproto.Response_OK
resp.Status = &status
client := int32(state.Client)
resp.Client = &client
//fmt.Println("Done setting value")
return resp
}
示例9: NeqConst
// Compare to const
func (state *ComputePeerState) NeqConst(action *sproto.Action) *sproto.Response {
//fmt.Println("Comparing to constant")
result := *action.Result
share0 := *action.Share0
val := *action.Value
share0val, hasShare0Val := state.SharesGet(share0)
rcode := *action.RequestCode
if !hasShare0Val {
//fmt.Printf("Failing, variable %s not found\n", share0)
return state.failResponse(action.GetRequestCode())
}
res := core.Sub(val, share0val)
//fmt.Printf("Subtractiong const %d", val)
res = state.neqz(res, rcode)
state.SharesSet(result, res)
//fmt.Printf("Done comparing to const\n")
return state.okResponse(action.GetRequestCode())
}
示例10: RemoveValue
// Remove the value for a share
func (state *ComputePeerState) RemoveValue(action *sproto.Action) *sproto.Response {
result := *action.Result
_, hasVal := state.SharesGet(result)
if hasVal {
//fmt.Println("Deleting value ", *action.Result)
result := *action.Result
state.SharesDelete(result)
//fmt.Println("Returned from sharesdelete")
resp := &sproto.Response{}
rcode := action.GetRequestCode()
resp.RequestCode = &rcode
status := sproto.Response_OK
resp.Status = &status
client := int32(state.Client)
resp.Client = &client
//fmt.Println("Done setting value")
return resp
}
return state.failResponse(action.GetRequestCode())
}
示例11: Mul
// Multiply two shares
func (state *ComputePeerState) Mul(action *sproto.Action) *sproto.Response {
//fmt.Println("Multiplying two values")
result := *action.Result
share0 := *action.Share0
share1 := *action.Share1
share0val, hasShare0val := state.SharesGet(share0)
share1val, hasShare1val := state.SharesGet(share1)
//fmt.Printf("Multiplying, will set %s\n", result)
rcode := *action.RequestCode
if hasShare0val && hasShare1val {
share := state.mul(share0val, share1val, rcode, 1)
//fmt.Printf("Done multiplying, setting %s\n", result)
state.SharesSet(result, share)
//fmt.Printf("Done multiplying, done setting %s\n", result)
//fmt.Printf("Done multiplying\n")
state.UnregisterChannelForRequest(*MakeRequestStep(rcode, 1))
return state.okResponse(action.GetRequestCode())
} else {
//fmt.Printf("Not setting %s, could not find operands %s %v %s %v\n", result, share0, hasShare0val, share1, hasShare1val)
}
return state.failResponse(action.GetRequestCode())
}
示例12: CmpConst
// Compare to const
func (state *ComputePeerState) CmpConst(action *sproto.Action) *sproto.Response {
//fmt.Println("Comparing to constant")
result := *action.Result
share0 := *action.Share0
val := *action.Value
share0val, hasShare0Val := state.SharesGet(share0)
rcode := *action.RequestCode
if !hasShare0Val {
return state.failResponse(action.GetRequestCode())
}
//fmt.Printf("For rcode %d (CMPCONST) subtracting\n", rcode)
res := core.Sub(val, share0val)
//fmt.Printf("For rcode %d (CMPCONST) neqz\n", rcode)
res = state.neqz(res, rcode)
//fmt.Printf("For rcode %d (CMPCONST) done with neqz\n", rcode)
one := int64(1)
//fmt.Printf("For rcode %d (CMPCONST) subtracting\n", rcode)
res = core.Sub(one, res)
//fmt.Printf("For rcode %d (CMPCONST) setting share\n", rcode)
state.SharesSet(result, res)
//fmt.Printf("Done comparing to const\n")
return state.okResponse(action.GetRequestCode())
}
示例13: DefaultAction
func (state *ComputePeerState) DefaultAction(action *sproto.Action) *sproto.Response {
//fmt.Println("Illegal action")
return state.failResponse(action.GetRequestCode())
}