func TestSingleMethodsDict(t *testing.T) {
	dict := coreprocessing.NewMethodInstructionDict()
	dict.RegisterClientMethods("test1", "test2")
	innerFunc := func() {
		newDict := coreprocessing.NewMethodInstructionDict()
		t.Logf("%p == %p ?", dict, newDict)
		if !newDict.Exists("test1") || !newDict.Exists("test2") {
			t.Error("Various instance!")
		}
	}
	innerFunc()
}
示例#2
0
func NewCoreWorkerManager(option options.SysOption, stat *statistic.Statistic) *CoreWorkerManager {
	// setup statistic items
	stat.AddItem("processed", "Processed messages count")
	stat.AddItem("skip_cmd", "Command with skip instruction count")
	manager := CoreWorkerManager{
		OutSignalChannel:        make(chan bool, 1),
		workerStopSignalChannel: make(chan bool, option.Workers),
		instructionsChannel:     make(chan coreprocessing.CoreInstruction, option.BufferSize),
		outChannels:             make([]*outChannelGroup, connectionsupport.GroupCount),
		methodsDict:             coreprocessing.NewMethodInstructionDict(),
		statistic:               stat,
		options:                 option}
	return &manager
}
示例#3
0
func ProcRegistration(handler *coreprocessing.Handler, inIns *coreprocessing.CoreInstruction) *coreprocessing.CoreInstruction {
	insType := coreprocessing.TypeInstructionSkip
	var answer *transport.Answer
	var result *coreprocessing.CoreInstruction
	var resultChanges *connectionsupport.StateChanges
	var errStr string
	errCode := 0
	if cmd, exists := inIns.GetCommand(); exists {
		info := ClientInfo{}
		if loadErr := json.Unmarshal([]byte((*cmd).Params.Json), &info); loadErr == nil {
			if (*handler).StateCheker.IsAuth(inIns.Cid) {
				// TODO: need implimentation for replace current cid to old
				switch info.Group {
				case connectionsupport.GroupConnectionClient:
					{
						changes := connectionsupport.StateChanges{
							ChangeType:            connectionsupport.StateChangesTypeGroup,
							ConnectionClientGroup: connectionsupport.GroupConnectionClient}
						resultChanges = &changes
						answer = inIns.MakeOkAnswer(
							fmt.Sprintf("{\"ok\": true, \"cid\": \"%s\"}", inIns.Cid))
					}
				case connectionsupport.GroupConnectionServer:
					{
						dict := coreprocessing.NewMethodInstructionDict()
						methodsCount := dict.RegisterClientMethods(info.Methods...)
						rpcManager := coreprocessing.NewRpcServerManager()
						rpcManager.Append(inIns.Cid, &(info.Methods))
						answer = inIns.MakeOkAnswer(
							fmt.Sprintf(
								"{\"methods_count\": %d, \"ok\": true, \"cid\": \"%s\"}",
								methodsCount, inIns.Cid))

						changes := connectionsupport.StateChanges{
							ChangeType:            connectionsupport.StateChangesTypeGroup,
							ConnectionClientGroup: connectionsupport.GroupConnectionServer}
						resultChanges = &changes
					}
				case connectionsupport.GroupConnectionWsClient:
					{
						// denied
						errCode = transport.ErrorCodeAccessDenied
						errStr = "Web-socket client don't accepted on simple TCP socket."
					}
				default:
					{
						errCode = transport.ErrorCodeUnexpectedValue
						errStr = "Unknown group, see the protocol specification."
					}
				}
			} else {
				errCode = transport.ErrorCodeAccessDenied
				errStr = "Access denied."
			}
		} else {
			errCode = transport.ErrorCodeMethodParamsFormatWrong
			errStr = fmt.Sprint(loadErr)
		}
	} else {
		errCode = transport.ErrorCodeCommandFormatWrong
		errStr = "Command is empty."
	}
	if errCode > 0 {
		insType = coreprocessing.TypeInstructionProblem
		answer = inIns.MakeErrAnswer(errCode, errStr)
	} else {
		insType = coreprocessing.TypeInstructionOk
	}
	result = coreprocessing.NewCoreInstruction(insType)
	result.SetAnswer(answer)
	result.StateChanges = resultChanges
	return result
}