当前位置: 首页>>代码示例>>Golang>>正文


Golang Message.MsgType方法代码示例

本文整理汇总了Golang中github.com/uhoh-itsmaciek/femebe/core.Message.MsgType方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.MsgType方法的具体用法?Golang Message.MsgType怎么用?Golang Message.MsgType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/uhoh-itsmaciek/femebe/core.Message的用法示例。


在下文中一共展示了Message.MsgType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: processIdentMsg

// Process the identity ('I') message, reporting the identity therein.
func processIdentMsg(msgInit msgInit, exit exitFn) string {
	var m core.Message

	msgInit(&m, exit)

	// Read the remote system identifier string
	if m.MsgType() != 'I' {
		exit("expected identification ('I') message, "+
			"but received %c", m.MsgType())
	}

	// hard-coded lengh limit, but it's very generous
	if m.Size() > 10*KB {
		log.Printf("oversized message string, msg size is %d",
			m.Size())
	}

	s, err := buf.ReadCString(m.Payload())
	if err != nil {
		exit("couldn't read identification string: %v",
			err)
	}

	return s
}
开发者ID:heroku,项目名称:pg_logplexcollector,代码行数:26,代码来源:logfebe.go

示例2: processVerMsg

// Read the version message, calling exit if this is not a supported
// version.
func processVerMsg(msgInit msgInit, exit exitFn) {
	var m core.Message

	msgInit(&m, exit)

	if m.MsgType() != 'V' {
		exit("expected version ('V') message, "+
			"but received %c", m.MsgType())
	}

	// hard-coded lengh limit, but it's very generous
	if m.Size() > 10*KB {
		log.Printf("oversized message string, msg size is %d",
			m.Size())
	}

	s, err := buf.ReadCString(m.Payload())
	if err != nil {
		exit("couldn't read version string: %v", err)
	}

	if !(strings.HasPrefix(s, "PG-9.0") ||
		strings.HasPrefix(s, "PG-9.1") ||
		strings.HasPrefix(s, "PG-9.2") ||
		strings.HasPrefix(s, "PG-9.3") ||
		strings.HasPrefix(s, "PG-9.4") ||
		strings.HasPrefix(s, "PG-9.5")) ||
		!strings.HasSuffix(s, "/logfebe-1") {
		exit("protocol version not supported: %s", s)
	}
}
开发者ID:heroku,项目名称:pg_logplexcollector,代码行数:33,代码来源:logfebe.go

示例3: discardUntilSync

func (c *FrontendConnection) discardUntilSync() error {
	var message fbcore.Message

	for {
		err := c.stream.Next(&message)
		if err != nil {
			return err
		}

		switch message.MsgType() {
		case fbproto.MsgSyncS:
			_, err = message.Force()
			return nil
		default:
			_, err = message.Force()
		}
		if err != nil {
			return err
		}
	}
}
开发者ID:geezer-workshop,项目名称:allas,代码行数:21,代码来源:frontendConnection.go

示例4: queryProcessingMainLoop

// This is the main loop for processing messages from the frontend.  Note that
// we must *never* send anything directly to the connection; all communication
// must go through queryResultCh.  We're also not responsible for doing any
// cleanup in any case; that'll all be handled by mainLoop.
func (c *FrontendConnection) queryProcessingMainLoop() {
	var unnamedStatement FrontendQuery

	var queryResult QueryResult
	var sendReadyForQuery bool

sessionLoop:
	for {
		var message fbcore.Message

		err := c.stream.Next(&message)
		if err != nil {
			c.setSessionError(err)
			break sessionLoop
		}

		queryResult = nil
		sendReadyForQuery = false

		switch message.MsgType() {
		case fbproto.MsgParseP:
			queryString, err := c.readParseMessage(&message)
			if err != nil {
				c.setSessionError(err)
				break sessionLoop
			}
			unnamedStatement, err = ParseQuery(queryString)
			if err != nil {
				queryResult = NewErrorResponse("42601", err.Error())
				c.queryResultCh <- queryResultSync{queryResult, false}

				err = c.discardUntilSync()
				if err != nil {
					c.setSessionError(err)
					break sessionLoop
				}

				queryResult = NewNopResponder()
				sendReadyForQuery = true
			} else {
				queryResult = NewParseComplete()
				sendReadyForQuery = false
			}

		case fbproto.MsgExecuteE:
			err = c.readExecuteMessage(&message)
			if unnamedStatement == nil {
				err = fmt.Errorf("attempted to execute the unnamed prepared statement when one does not exist")
				c.setSessionError(err)
				break sessionLoop
			}
			queryResult, err = unnamedStatement.Process(c)
			if err != nil {
				c.setSessionError(err)
				break sessionLoop
			}
			sendReadyForQuery = false
			// Disallow reuse; not exactly following the protocol to the letter,
			// but apps reusing the unnamed statement should not exist, either.
			unnamedStatement = nil

		case fbproto.MsgDescribeD:
			_, err = c.readDescribeMessage(&message)
			if err != nil {
				c.setSessionError(err)
				break sessionLoop
			}
			if unnamedStatement == nil {
				err = fmt.Errorf("attempted to describe the unnamed prepared statement when one does not exist")
				c.setSessionError(err)
				break sessionLoop
			}
			queryResult = unnamedStatement.Describe()
			sendReadyForQuery = false

		case fbproto.MsgBindB:
			err = c.readBindMessage(&message)
			if err != nil {
				c.setSessionError(err)
				break sessionLoop
			}
			queryResult = NewBindComplete()
			sendReadyForQuery = false

		case fbproto.MsgSyncS:
			queryResult = NewNopResponder()
			sendReadyForQuery = true

		case fbproto.MsgQueryQ:
			query, err := fbproto.ReadQuery(&message)
			if err != nil {
				c.setSessionError(err)
				break sessionLoop
			}
			q, err := ParseQuery(query.Query)
			if err != nil {
//.........这里部分代码省略.........
开发者ID:geezer-workshop,项目名称:allas,代码行数:101,代码来源:frontendConnection.go

示例5: startup

func (c *FrontendConnection) startup(startupParameters map[string]string, dbcfg VirtualDatabaseConfiguration) bool {
	var message fbcore.Message
	var err error

	for {
		err = c.stream.Next(&message)
		if err != nil {
			elog.Logf("error while reading startup packet: %s", err)
			return false
		}
		if fbproto.IsStartupMessage(&message) {
			break
		} else if fbproto.IsSSLRequest(&message) {
			_, err = message.Force()
			if err != nil {
				elog.Logf("error while reading SSLRequest: %s", err)
				return false
			}
			err = c.stream.SendSSLRequestResponse(fbcore.RejectSSLRequest)
			if err != nil {
				elog.Logf("error during startup sequence: %s", err)
				return false
			}
			err = c.FlushStream()
			if err != nil {
				elog.Logf("error during startup sequence: %s", err)
			}
		} else if fbproto.IsCancelRequest(&message) {
			_ = c.stream.Close()
			return false
		} else {
			elog.Warningf("unrecognized frontend message type 0x%x during startup", message.MsgType())
			return false
		}
	}
	sm, err := fbproto.ReadStartupMessage(&message)
	if err != nil {
		elog.Logf("error while reading startup packet: %s", err)
		return false
	}

	if !c.auth(dbcfg, sm) {
		// error already logged
		_ = c.stream.Close()
		return false
	}

	fbproto.InitAuthenticationOk(&message)
	err = c.WriteMessage(&message)
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}

	for k, v := range startupParameters {
		buf := &bytes.Buffer{}
		fbbuf.WriteCString(buf, k)
		fbbuf.WriteCString(buf, v)
		message.InitFromBytes(fbproto.MsgParameterStatusS, buf.Bytes())
		err = c.WriteMessage(&message)
		if err != nil {
			elog.Logf("error during startup sequence: %s", err)
			return false
		}
	}

	fbproto.InitReadyForQuery(&message, fbproto.RfqIdle)
	err = c.WriteMessage(&message)
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}

	err = c.FlushStream()
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}
	return true
}
开发者ID:geezer-workshop,项目名称:allas,代码行数:80,代码来源:frontendConnection.go

示例6: auth

func (c *FrontendConnection) auth(dbcfg VirtualDatabaseConfiguration, sm *fbproto.StartupMessage) bool {
	authFailed := func(sqlstate, format string, v ...interface{}) bool {
		var msg fbcore.Message
		message := fmt.Sprintf(format, v...)
		initFatalMessage(&msg, sqlstate, message)
		_ = c.WriteMessage(&msg)
		_ = c.FlushStream()
		return false
	}

	username, ok := sm.Params["user"]
	if !ok {
		return authFailed("08P01", `required startup parameter "user" nor present in startup packet`)
	}
	dbname, ok := sm.Params["database"]
	if !ok {
		dbname = username
	}
	authMethod, ok := dbcfg.FindDatabase(dbname)
	if !ok {
		return authFailed("3D000", "database %q does not exist", dbname)
	}

	switch authMethod {
	case "trust":
		return true
	case "md5":
		// handled below
	default:
		elog.Errorf("unrecognized authentication method %q", authMethod)
		return authFailed("XX000", "internal error")
	}

	salt := make([]byte, 4)
	_, err := rand.Read(salt)
	if err != nil {
		elog.Errorf("could not generate random salt: %s", err)
		return authFailed("XX000", "internal error")
	}

	var msg fbcore.Message
	buf := &bytes.Buffer{}
	fbbuf.WriteInt32(buf, 5)
	buf.Write(salt)
	msg.InitFromBytes(fbproto.MsgAuthenticationMD5PasswordR, buf.Bytes())
	err = c.WriteAndFlush(&msg)
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}
	err = c.stream.Next(&msg)
	if err == io.EOF {
		elog.Debugf("EOF during startup sequence")
		return false
	} else if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}
	if msg.MsgType() != fbproto.MsgPasswordMessageP {
		return authFailed("08P01", "unexpected response %x", msg.MsgType())
	}
	// don't bother with messages which are clearly too big
	if msg.Size() > 100 {
		return authFailed("28001", "password authentication failed for user %q", username)
	}
	password, err := msg.Force()
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}
	success, err := dbcfg.MD5Auth(dbname, username, salt, password)
	if err != nil {
		elog.Logf("error during startup sequence: %s", err)
		return false
	}
	if !success {
		return authFailed("28001", "password authentication failed for user %q", username)
	}
	return true
}
开发者ID:geezer-workshop,项目名称:allas,代码行数:80,代码来源:frontendConnection.go


注:本文中的github.com/uhoh-itsmaciek/femebe/core.Message.MsgType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。