Example #1
0
// newConn creates a new *clientConn from a net.Conn.
// It allocates a connection ID and random salt data for authentication.
func (s *Server) newConn(conn net.Conn) *clientConn {
	cc := &clientConn{
		conn:         conn,
		pkt:          newPacketIO(conn),
		server:       s,
		connectionID: atomic.AddUint32(&baseConnID, 1),
		collation:    mysql.DefaultCollationID,
		alloc:        arena.NewAllocator(32 * 1024),
	}
	log.Infof("[%d] new connection %s", cc.connectionID, conn.RemoteAddr().String())
	cc.salt = randomBuf(20)
	return cc
}
Example #2
0
func (s *Server) newConn(conn net.Conn) (cc *clientConn, err error) {
	log.Info("newConn", conn.RemoteAddr().String())
	cc = &clientConn{
		conn:         conn,
		pkg:          newPacketIO(conn),
		server:       s,
		connectionID: atomic.AddUint32(&baseConnID, 1),
		collation:    mysql.DefaultCollationID,
		charset:      mysql.DefaultCharset,
		alloc:        arena.NewAllocator(32 * 1024),
	}
	cc.salt = randomBuf(20)
	return
}
Example #3
0
func (r *Replayer) replayRecord() error {
	record, err := r.readRecord()
	if err != nil {
		return errors.Trace(err)
	}

	switch record.Type {
	case ConnCreateRecord:
		if _, ok := r.clients[record.ConnectionID]; ok {
			return errors.Errorf("duplicated connection id for %s", record)
		}
		conn := new(ClientConn)
		err = conn.Unmarshal(record.Data)
		if err != nil {
			return errors.Trace(err)
		}
		conn.pkg = &dummyPacket{}
		conn.recWriter = r.recWriter
		conn.alloc = arena.NewAllocator(32 * 1024)
		conn.ctx, err = r.driver.OpenCtx(conn.Capability, conn.Collation, conn.DBName)
		if err != nil {
			return errors.Trace(err)
		}
		r.clients[conn.ConnectionID] = conn
	case ConnDeleteRecord:
		conn, ok := r.clients[record.ConnectionID]
		if !ok {
			return errors.Errorf("missing connection for %s", record)
		}
		delete(r.clients, record.ConnectionID)
		conn.Close()
	case ConnRequestRecord:
		conn, ok := r.clients[record.ConnectionID]
		if !ok {
			return errors.Errorf("missing connection for %s", record)
		}

		conn.HandleRequest(record.Data)
	case ConnResponseRecord:
		_, ok := r.clients[record.ConnectionID]
		if !ok {
			return errors.Errorf("missing connection for %s", record)
		}
	default:
		return errors.Errorf("invalid record %s", record)
	}

	return r.err
}
Example #4
0
func (s *Server) newConn(conn net.Conn) (cc *clientConn, err error) {
	log.Info("newConn", conn.RemoteAddr().String())
	cc = &clientConn{
		conn:         conn,
		pkg:          newPacketIO(conn),
		server:       s,
		connectionID: atomic.AddUint32(&baseConnID, 1),
		collation:    mysql.DefaultCollationID,
		charset:      mysql.DefaultCharset,
		alloc:        arena.NewAllocator(32 * 1024),
	}
	cc.salt = make([]byte, 20)
	io.ReadFull(rand.Reader, cc.salt)
	for i, b := range cc.salt {
		if b == 0 {
			cc.salt[i] = '0'
		}
	}
	return
}