Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api_gateway]Add connection query API #822

Merged
merged 2 commits into from
Sep 17, 2018

Conversation

MakeHoney
Copy link
Contributor

Issue
#820

Component
api_gateway

Descriptions
add codes for connection query API that can helps users know connection state with peers.

@MakeHoney
Copy link
Contributor Author

테스트 케이스 작성해보겠습니다 :0

}

func (cr *ConnectionRepository) CreateConnection(connCreated event.ConnectionCreated) error {
cr.mux.Lock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create보다는 Save(connCreated event.ConnectionCreated) error로 수정해주세요!!
생성이 아니라 connection을 저장하기 때문에 save라는 이름이 좋을 것 같습니다.


_, exist := cr.ConnectionTable[connCreated.ConnectionId]

if exist {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40,42번째 두 라인 붙여주세요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아.. 또 깜빡했네요!

return nil
}

func (cr *ConnectionRepository) CloseConnection(connClosed event.ConnectionClosed) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수이름을 close보다 delete or remove로 해주세요!! 다른 파일들참조해서 이름을 맞춰주세요!!

@MakeHoney
Copy link
Contributor Author

  • 테스트 케이스를 추가했습니다.
  • 세마포를 카피하면 안된다는 경고가 나와서 레퍼런스로 전달하였습니다.
  • ConnectionId 라는 구조체 멤버명이 ConnectionID와 혼선이 있어서 ConnectionID로 통일하였습니다.

travis는 왜 통과가 안될까요..흑..

@ttkmw
Copy link
Collaborator

ttkmw commented Sep 15, 2018

p2p/infra/adapter/event_handler.go:78:47: event.ConnectionId undefined (type event.ConnectionClosed has no field or method ConnectionId, but does have ConnectionID)
FAIL github.com/it-chain/engine/p2p [build failed]

connectionId 부분에서 오류가 나네요!

아마 ConnectionID로 통일하시는 부분에서 일부분 수정이 안된게아닐까 싶습니다!

@MakeHoney
Copy link
Contributor Author

컴파일만해보고 런타임은 확인 못했네요 ㅜㅜ 수정하겠습니다..!

@junbeomlee
Copy link
Member

큰 문제가 하나있습니다!!... 제가 제대로 못 알려드렸는데
connectionQueryApi 에서는 getAllConnectionList같은 조회용 함수들이 있어야하고, repository에 save하는 것은 eventHandler에서 처리되어야 합니다.

func (q ConnectionQueryApi) FindAllConnection() error {
	return q.connectionRepository.FindAll()
}
 func (q ConnectionQueryApi) FindConnection(connID string) error {
	return q.connectionRepository.Find(connID)
}

그리고

type ConnectionEventListener struct {
	connectionRepository ConnectionRepository
}
 func NewConnectionEventListener(connRepository connRepository) ConnectionEventListener {
	return ConnectionEventListener{
		connectionRepository: connRepository,
	}
}

 func (cel *ConnectionEventListener) HandleConnectionCreatedEvent(event event.ConnectionCreated) error {
	connection := Connection{
		ConnectionID: event.ConnectionID,
		Address:      event.Address,
	}
 	err := cel.connRepository.Save(connection)
	if err != nil {
		return err
	}
	return nil
}
 func (cel *ConnectionEventListener) HandleConnectionClosedEvent(event event.ConnectionClosed) error {
	cel.connRepository.Remove(event.ConnectionID)
	return nil
}

이러식으로 수정 부탁드립니다!

@junbeomlee junbeomlee merged commit f45bca6 into DE-labtory:develop Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants