func (r *Relayer) Receive(f *Frame, fType frameType) (sent bool, failureReason string) {
	id := f.Header.ID

	// If we receive a response frame, we expect to find that ID in our outbound.
	// If we receive a request frame, we expect to find that ID in our inbound.
	items := r.receiverItems(fType)

	item, ok := items.Get(id)
	if !ok {
		r.logger.WithFields(
			LogField{"id", id},
		).Warn("Received a frame without a RelayItem.")
		return false, _relayErrorNotFound
	}

	finished := finishesCall(f)
	if item.tomb {
		// Call timed out, ignore this frame. (We've already handled stats.)
		// TODO: metrics for late-arriving frames.
		return true, ""
	}

	// call res frames don't include the OK bit, so we can't wait until the last
	// frame of a relayed RPC to determine if the call succeeded.
	if fType == responseFrame {
		// If we've gotten a response frame, we're the originating relayer and
		// should handle stats.
		if succeeded, failMsg := determinesCallSuccess(f); succeeded {
			item.call.Succeeded()
		} else if len(failMsg) > 0 {
			item.call.Failed(failMsg)
		}
	}
	select {
	case r.conn.sendCh <- f:
	default:
		// Buffer is full, so drop this frame and cancel the call.
		r.logger.WithFields(
			LogField{"id", id},
		).Warn("Dropping call due to slow connection.")

		items := r.receiverItems(fType)

		err := _relayErrorDestConnSlow
		// If we're dealing with a response frame, then the client is slow.
		if fType == responseFrame {
			err = _relayErrorSourceConnSlow
		}

		r.failRelayItem(items, id, err)
		return false, err
	}

	if finished {
		r.finishRelayItem(items, id)
	}

	return true, ""
}
func (r *Relayer) Receive(f *Frame, fType frameType) (sent bool, failureReason string) {
	id := f.Header.ID

	
	
	items := r.receiverItems(fType)

	item, ok := items.Get(id)
	if !ok {
		r.logger.WithFields(
			LogField{"id", id},
		).Warn("Received a frame without a RelayItem.")
		return false, _relayErrorNotFound
	}

	finished := finishesCall(f)
	if item.tomb {
		
		
		return true, ""
	}

	
	
	if fType == responseFrame {
		
		
		if succeeded, failMsg := determinesCallSuccess(f); succeeded {
			item.call.Succeeded()
		} else if len(failMsg) > 0 {
			item.call.Failed(failMsg)
		}
	}
	select {
	case r.conn.sendCh <- f:
	default:
		
		r.logger.WithFields(
			LogField{"id", id},
		).Warn("Dropping call due to slow connection.")

		items := r.receiverItems(fType)

		err := _relayErrorDestConnSlow
		
		if fType == responseFrame {
			err = _relayErrorSourceConnSlow
		}

		r.failRelayItem(items, id, err)
		return false, err
	}

	if finished {
		r.finishRelayItem(items, id)
	}

	return true, ""
}
func ( r * Relayer ) Receive ( f * Frame , fType frameType ) ( sent bool , failureReason string ) { id := f . Header . ID // If we receive a response frame, we expect to find that ID in our outbound. // If we receive a request frame, we expect to find that ID in our inbound. items := r . receiverItems ( fType ) item , ok := items . Get ( id ) if ! ok { r . logger . WithFields ( LogField { " " , id } , ) . Warn ( " " ) return false , _relayErrorNotFound } finished := finishesCall ( f ) if item . tomb { // Call timed out, ignore this frame. (We've already handled stats.) // TODO: metrics for late-arriving frames. return true , " " } // call res frames don't include the OK bit, so we can't wait until the last // frame of a relayed RPC to determine if the call succeeded. if fType == responseFrame { // If we've gotten a response frame, we're the originating relayer and // should handle stats. if succeeded , failMsg := determinesCallSuccess ( f ) ; succeeded { item . call . Succeeded ( ) } else if len ( failMsg ) > 0 { item . call . Failed ( failMsg ) } } select { case r . conn . sendCh <- f : default : // Buffer is full, so drop this frame and cancel the call. r . logger . WithFields ( LogField { " " , id } , ) . Warn ( " " ) items := r . receiverItems ( fType ) err := _relayErrorDestConnSlow // If we're dealing with a response frame, then the client is slow. if fType == responseFrame { err = _relayErrorSourceConnSlow } r . failRelayItem ( items , id , err ) return false , err } if finished { r . finishRelayItem ( items , id ) } return true , " " }
// Receive receives frames intended for this connection.
// It returns whether the frame was sent and a reason for failure if it failed.
Receive receives frames intended for this connection . It returns whether the frame was sent and a reason for failure if it failed .